home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / automake.0 / automake / automake-1.0 / automake.in < prev    next >
Encoding:
Text File  |  1996-05-25  |  79.9 KB  |  3,135 lines

  1. #!@PERL@
  2. # -*- perl -*-
  3. # @configure_input@
  4.  
  5. eval 'exec @PERL@ -S $0 ${1+"$@"}'
  6.     if 0;
  7.  
  8. # automake - create Makefile.in from Makefile.am
  9. # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
  10.  
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2, or (at your option)
  14. # any later version.
  15.  
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. # GNU General Public License for more details.
  20.  
  21. # You should have received a copy of the GNU General Public License
  22. # along with this program; if not, write to the Free Software
  23. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  24. # 02111-1307, USA.
  25.  
  26. # Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
  27. # Perl reimplementation by Tom Tromey <tromey@drip.colorado.edu>.
  28.  
  29.  
  30. # Parameters set by configure.  Not to be changed.  NOTE: assign
  31. # VERSION as string so that eg version 0.30 will print correctly.
  32. $VERSION = "@VERSION@";
  33. $prefix = "@prefix@";
  34. $am_dir = "@datadir@/@PACKAGE@";
  35.  
  36. # String constants.
  37. $IGNORE_PATTERN = "^##([^#].*)?\$";
  38. $WHITE_PATTERN = "^[ \t]*\$";
  39. $COMMENT_PATTERN = "^#";
  40. $RULE_PATTERN = "^([\$a-zA-Z_.][-.a-zA-Z0-9_(){}/]*) *:";
  41. $MACRO_PATTERN = "^([A-Za-z][A-Za-z0-9_]*)[ \t]*=[ \t]*(.*)\$";
  42. $BOGUS_MACRO_PATTERN = "^([^ \t]*)[ \t]*=[ \t]*(.*)\$";
  43.  
  44. # Constants to define the "strictness" level.
  45. $FOREIGN = 0;
  46. $GNU = 1;
  47. $GNITS = 2;
  48.  
  49.  
  50.  
  51. # Variables global to entire run.
  52.  
  53. # Strictness level as set on command line.
  54. $default_strictness = $GNU;
  55.  
  56. # Name of strictness level, as set on command line.
  57. $default_strictness_name = 'gnu';
  58.  
  59. # This is TRUE if GNU make specific automatic dependency generation
  60. # code should be included in generated Makefile.in.
  61. $cmdline_use_dependencies = 1;
  62.  
  63. # TRUE if in verbose mode.
  64. $verbose = 0;
  65.  
  66. # This holds our (eventual) exit status.  We don't actually exit until
  67. # we have processed all input files.
  68. $exit_status = 0;
  69.  
  70. # From the Perl manual.
  71. $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
  72.  
  73. # TRUE if missing standard files should be installed.
  74. $add_missing = 0;
  75.  
  76. # Files found by scanning configure.in for LIBOBJS.
  77. %libsources = ();
  78.  
  79. # True if fp_C_PROTOTYPES appears in configure.in.
  80. $fp_c_prototypes = 0;
  81.  
  82. # Names used in AC_CONFIG_HEADER call.  $config_name is the actual
  83. # (first) argument.  $config_header is the '.in' file.  Ordinarily the
  84. # second is derived from the first, but they can be different if the
  85. # weird "NAME:FILE" syntax is used.
  86. $config_name = '';
  87. $config_header = '';
  88. # Line number at which AC_CONFIG_HEADER appears in configure.in.
  89. $config_header_line = 0;
  90.  
  91. # Directory where output files go.  Actually, output files are
  92. # relative to this directory.
  93. $output_directory = '.';
  94.  
  95. # Relative location of top build directory.
  96. $top_builddir = '';
  97.  
  98. # List of Makefile.am's to process.
  99. @input_files = ();
  100.  
  101. # List of files in AC_OUTPUT without Makefile.am.
  102. @other_input_files = ();
  103. # Line number at which AC_OUTPUT seen.
  104. $ac_output_line = 0;
  105.  
  106. # List of directories to search for configure-required files.  This
  107. # can be set by AC_CONFIG_AUX_DIR.
  108. @config_aux_path = ('.', '..', '../..');
  109. $config_aux_dir = '';
  110.  
  111. # Whether AC_PROG_MAKE_SET has been seen in configure.in.
  112. $seen_make_set = 0;
  113.  
  114. # Whether ud_GNU_GETTEXT has been seen in configure.in.
  115. $seen_gettext = 0;
  116. # Line number at which ud_GNU_GETTEXT seen.
  117. $ac_gettext_line = 0;
  118.  
  119. # Whether ALL_LINGUAS has been seen.
  120. $seen_linguas = '';
  121. # The actual text.
  122. $all_linguas = '';
  123. # Line number at which it appears.
  124. $all_linguas_line = 0;
  125.  
  126. # 1 if AC_PROG_INSTALL seen, 2 if fp_PROG_INSTALL seen.
  127. $seen_prog_install = 0;
  128.  
  129. # 1 if any scripts installed, 0 otherwise.
  130. $scripts_installed = 0;
  131.  
  132. # Whether AC_PATH_XTRA has been seen in configure.in.
  133. $seen_path_xtra = 0;
  134.  
  135. # Whether YACC variable has been seen in configure.in.
  136. $seen_prog_yacc = 0;
  137.  
  138. # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
  139. # AC_CHECK_TOOL also sets this.
  140. $seen_canonical = 0;
  141.  
  142. # TRUE if we've seen AC_PROG_RANLIB.
  143. $seen_ranlib = 0;
  144.  
  145. # TRUE if we've seen AC_ARG_PROGRAM.
  146. $seen_arg_prog = 0;
  147.  
  148. # TRUE if we've seen gm_PROG_LIBTOOL or AC_PROG_LIBTOOL.
  149. $seen_libtool = 0;
  150. $libtool_line = 0;
  151.  
  152. # TRUE if we've seen jm_MAINTAINER_MODE.
  153. $seen_maint_mode = 0;
  154.  
  155. # TRUE if we've seen PACKAGE and VERSION.
  156. $seen_package = 0;
  157. $seen_version = 0;
  158.  
  159.  
  160. # Charsets used by maintainer and in distribution.  MAINT_CHARSET is
  161. # handled in a funny way: if seen in the top-level Makefile.am, it is
  162. # used for every directory which does not specify a different value.
  163. # The rationale here is that some directories (eg gettext) might be
  164. # distributions of other packages, and thus require their own charset
  165. # info.  However, the DIST_CHARSET must be the same for the entire
  166. # package; it can only be set at top-level.
  167. # FIXME this yields bugs when rebuilding.  What to do?  Always
  168. # read (and sometimes discard) top-level Makefile.am?
  169. $maint_charset = '';
  170. $dist_charset = 'utf8';        # recode doesn't support this yet.
  171.  
  172. # Name of input file ("Makefile.in") and output file ("Makefile.am").
  173. # These have no directory components.
  174. $am_file_name = '';
  175. $in_file_name = '';
  176.  
  177.  
  178.  
  179. &initialize_global_constants;
  180.  
  181. # Parse command line.
  182. &parse_arguments (@ARGV);
  183.  
  184. # Do configure.in scan only once.
  185. &scan_configure;
  186.  
  187. die "automake: no \`Makefile.am' found or specified\n"
  188.     if ! @input_files;
  189.  
  190. # Now do all the work on each file.
  191. foreach $am_file (@input_files)
  192. {
  193.     # FIXME should support the AC_OUTPUT ":" syntax here.
  194.     if (! -f ($am_file . '.am'))
  195.     {
  196.     &am_error ('no such file');
  197.     }
  198.     else
  199.     {
  200.     &generate_makefile ($am_file);
  201.     }
  202. }
  203.  
  204. if ($seen_prog_install <= $scripts_installed)
  205. {
  206.     &am_conf_error (($scripts_installed ? 'fp_PROG_INSTALL' : 'AC_PROG_INSTALL')
  207.             . " must be used in configure.in");
  208.     &keyed_aclocal_warning ('fp_PROG_INSTALL')
  209.     if $scripts_installed;
  210. }
  211.  
  212. exit $exit_status;
  213.  
  214.  
  215. ################################################################
  216.  
  217. # Parse command line.
  218. sub parse_arguments
  219. {
  220.     local (@arglist) = @_;
  221.  
  222.     # Start off as gnu.
  223.     &set_strictness ('gnu');
  224.  
  225.     while (@arglist)
  226.     {
  227.     if ($arglist[0] eq "--version")
  228.     {
  229.         print "Automake version $VERSION\n";
  230.         exit 0;
  231.     }
  232.     elsif ($arglist[0] eq "--help")
  233.     {
  234.         &usage;
  235.     }
  236.     elsif ($arglist[0] =~ /^--amdir=(.+)$/)
  237.     {
  238.         $am_dir = $1;
  239.     }
  240.     elsif ($arglist[0] eq '--amdir')
  241.     {
  242.         &require_argument (@arglist);
  243.         shift (@arglist);
  244.         $am_dir = $arglist[0];
  245.     }
  246.     elsif ($arglist[0] =~ /^--strictness=(.+)$/)
  247.     {
  248.         &set_strictness ($1);
  249.     }
  250.     elsif ($arglist[0] eq '--gnu')
  251.     {
  252.         &set_strictness ('gnu');
  253.     }
  254.     elsif ($arglist[0] eq '--gnits')
  255.     {
  256.         &set_strictness ('gnits');
  257.     }
  258.     elsif ($arglist[0] eq '--foreign')
  259.     {
  260.         &set_strictness ('foreign');
  261.     }
  262.     elsif ($arglist[0] eq '--strictness' || $arglist[0] eq '-s')
  263.     {
  264.         &require_argument (@arglist);
  265.         shift (@arglist);
  266.         &set_strictness ($arglist[0]);
  267.     }
  268.     elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
  269.     {
  270.         $cmdline_use_dependencies = 0;
  271.     }
  272.     elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
  273.     {
  274.         # Set output directory.
  275.         $output_directory = $1;
  276.     }
  277.     elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
  278.     {
  279.         &require_argument (@arglist);
  280.         shift (@arglist);
  281.         $output_directory = $arglist[0];
  282.     }
  283.     elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
  284.     {
  285.         $add_missing = 1;
  286.     }
  287.     elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
  288.     {
  289.         $verbose = 1;
  290.     }
  291.     elsif ($arglist[0] eq '--')
  292.     {
  293.         # Stop option processing.
  294.         shift (@arglist);
  295.         push (@input_files, @arglist);
  296.         last;
  297.     }
  298.     elsif ($arglist[0] =~ /^-/)
  299.     {
  300.         die "automake: unrecognized option -- \`$arglist[0]'\n";
  301.     }
  302.     else
  303.     {
  304.         push (@input_files, $arglist[0]);
  305.     }
  306.  
  307.     shift (@arglist);
  308.     }
  309.  
  310.     # Take global strictness from whatever we currently have set.
  311.     $default_strictness = $strictness;
  312.     $default_strictness_name = $strictness_name;
  313. }
  314.  
  315. # Ensure argument exists, or die.
  316. sub require_argument
  317. {
  318.     local ($arg, @arglist) = @_;
  319.     die "automake: no argument given for option \`$arg'\n"
  320.     if ! @arglist;
  321. }
  322.  
  323. ################################################################
  324.  
  325. # Generate a Makefile.in given the name of the corresponding Makefile.
  326. sub generate_makefile
  327. {
  328.     local ($makefile) = @_;
  329.  
  330.     ($am_file_name = $makefile) =~ s/^.*\///;
  331.     $in_file_name = $am_file_name . '.in';
  332.     $am_file_name .= '.am';
  333.  
  334.     print "automake: creating ", $makefile, ".in\n" if $verbose;
  335.  
  336.     &initialize_per_input;
  337.     $relative_dir = &dirname ($makefile);
  338.  
  339.     # At the toplevel directory, we might need config.guess, config.sub
  340.     # or libtool.
  341.     if ($relative_dir eq '.')
  342.     {
  343.      # libtool requires some files.
  344.      &require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
  345.                         'config.sub', 'config.guess',
  346.                         'libtool') if $seen_libtool;
  347.  
  348.         # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
  349.         # config.sub.
  350.         &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
  351.         if $seen_canonical;
  352.     }
  353.  
  354.     # We still need Makefile.in here, because sometimes the `dist'
  355.     # target doesn't re-run automake.
  356.     &push_dist_common ($in_file_name, $am_file_name);
  357.     push (@sources, '$(SOURCES)')
  358.     if &variable_defined ('SOURCES');
  359.     push (@objects, '$(OBJECTS)')
  360.     if &variable_defined ('OBJECTS');
  361.  
  362.     # This is always the default target.  This gives us freedom to do
  363.     # things in whatever order is convenient.
  364.     $output_rules .= "default: all\n\n";
  365.     push (@phony, 'default');
  366.  
  367.     &read_am_file ($makefile . '.am');
  368.     &handle_options;
  369.  
  370.     # Check first, because we might modify some state.
  371.     &check_gnu_standards;
  372.     &check_gnits_standards;
  373.  
  374.     &handle_configure;
  375.     &handle_gettext;
  376.     &handle_libraries;
  377.     &handle_programs;
  378.     &handle_scripts;
  379.  
  380.     # Re-init SOURCES and OBJECTS.  FIXME other code shouldn't depend
  381.     # on this (but currently does).
  382.     $contents{'SOURCES'} = join (' ', @sources);
  383.     $contents{'OBJECTS'} = join (' ', @objects);
  384.  
  385.     &handle_texinfo;
  386.     &handle_man_pages;
  387.     &handle_data;
  388.     &handle_headers;
  389.     &handle_subdirs;
  390.     &handle_tags;
  391.     &handle_dist;
  392.     &handle_dependencies;
  393.     &handle_tests;
  394.     &handle_footer;
  395.     &handle_merge_targets;
  396.     &handle_installdirs;
  397.     &handle_clean;
  398.     &handle_phony;
  399.  
  400.     if (! -d ($output_directory . '/' . $relative_dir))
  401.     {
  402.     &mkdir ($output_directory . '/' . $relative_dir);
  403.     }
  404.     if (! open (GM_FILE, "> " . $output_directory . '/' . $makefile . ".in"))
  405.     {
  406.     warn "automake: ${am_file}.in: cannot open: $!\n";
  407.     $exit_status = 1;
  408.     return;
  409.     }
  410.  
  411.     print GM_FILE $output_vars;
  412.     print GM_FILE $output_rules;
  413.     print GM_FILE $output_trailer;
  414.  
  415.     close (GM_FILE);
  416. }
  417.  
  418. ################################################################
  419.  
  420. # Handle AUTOMAKE_OPTIONS variable.
  421. sub handle_options
  422. {
  423.     return if ! &variable_defined ('AUTOMAKE_OPTIONS');
  424.  
  425.     foreach (split (' ', $contents{'AUTOMAKE_OPTIONS'}))
  426.     {
  427.     $options{$_} = 1;
  428.     if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
  429.     {
  430.         &set_strictness ($_);
  431.     }
  432.     elsif ($_ eq 'no-installman' || $_ eq 'ansi2knr'
  433.            || $_ eq 'dist-shar' || $_ eq 'dist-zip'
  434.            || $_ eq 'dejagnu')
  435.     {
  436.         # Explicitly recognize these.
  437.     }
  438.     elsif ($_ eq 'no-dependencies')
  439.     {
  440.         $use_dependencies = 0;
  441.     }
  442.     elsif (/[0-9]+\.?[0-9]+/)
  443.     {
  444.         # Got a version number.  Is the syntax too strict?
  445.         if ($VERSION < $_)
  446.         {
  447.         &am_line_error ('AUTOMAKE_OPTIONS',
  448.                 "require version $_, only have $VERSION");
  449.         exit 1;
  450.         }
  451.     }
  452.     else
  453.     {
  454.         &am_line_error ('AUTOMAKE_OPTIONS',
  455.                 'option ', $_, 'not recognized');
  456.     }
  457.     }
  458. }
  459.  
  460. # Return object extension.  Just once, put some code into the output.
  461. sub get_object_extension
  462. {
  463.     if (! $dir_holds_sources)
  464.     {
  465.     # Boilerplate.
  466.     local ($xform) = '';
  467.     if (&variable_defined ('CONFIG_HEADER'))
  468.     {
  469.         ($xform = &dirname ($contents{'CONFIG_HEADER'}))
  470.         =~ s/(\W)/\\$1/g;
  471.         $xform = '-I' . $xform;
  472.     }
  473.     $xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go';
  474.     $output_vars .= &file_contents_with_transform ($xform,
  475.                                'compile-vars');
  476.     $output_rules .= &file_contents ('compile');
  477.     &push_phony_cleaners ('compile');
  478.  
  479.     # If using X, include some extra variable definitions.  NOTE
  480.     # we don't want to force these into CFLAGS or anything,
  481.     # because not all programs will necessarily use X.
  482.     if ($seen_path_xtra)
  483.     {
  484.         $output_vars .= ("X_CFLAGS = \@X_CFLAGS\@\n"
  485.                  . "X_LIBS = \@X_LIBS\@\n"
  486.                  . "X_EXTRA_LIBS = \@X_EXTRA_LIBS\@\n"
  487.                  . "X_PRE_LIBS = \@X_PRE_LIBS\@\n");
  488.     }
  489.  
  490.     # Check for automatic de-ANSI-fication.
  491.     $dir_holds_sources = '.o';
  492.     push (@suffixes, '.c', '.o');
  493.     push (@clean, 'compile');
  494.  
  495.     if (defined $options{'ansi2knr'})
  496.     {
  497.         if (! $fp_c_prototypes)
  498.         {
  499.         &am_line_error ('AUTOMAKE_OPTIONS',
  500.                 "option \`ansi2knr' in use but \`fp_C_PROTOTYPES' not in configure.in");
  501.         &keyed_aclocal_warning ('fp_C_PROTOTYPES');
  502.         # Only give this error once.
  503.         $fp_c_prototypes = 1;
  504.         }
  505.  
  506.         $dir_holds_sources = '$o';
  507.         push (@suffixes, '._c', '._o');
  508.  
  509.         &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
  510.                      'ansi2knr.c', 'ansi2knr.1');
  511.  
  512.         $output_vars .= &file_contents ('kr-vars');
  513.         $output_rules .= &file_contents ('compile-kr');
  514.         $output_rules .= &file_contents ('clean-kr');
  515.  
  516.         push (@clean, 'kr');
  517.         &push_phony_cleaners ('kr');
  518.     }
  519.     }
  520.     return $dir_holds_sources;
  521. }
  522.  
  523. # Handle SOURCE->OBJECT transform for one program or library.
  524. sub handle_source_transform
  525. {
  526.     # one_file is canonical name.  unxformed is given name.  obj is
  527.     # object extension.
  528.     local ($one_file, $unxformed, $obj) = @_;
  529.     local ($objpat) = $obj;
  530.     $objpat =~ s/(\W)/\\$1/g;
  531.  
  532.     if (&variable_defined ($one_file . "_OBJECTS"))
  533.     {
  534.     &am_line_error ($one_file . '_OBJECTS',
  535.             $one_file . '_OBJECTS', 'should not be defined');
  536.     # No point in continuing.
  537.     return;
  538.     }
  539.  
  540.     local ($source_list);
  541.     local ($prefix);
  542.     foreach $prefix ('', 'EXTRA_')
  543.     {
  544.     $source_list = '';
  545.     if (&variable_defined ($prefix . $one_file . "_SOURCES"))
  546.     {
  547.         push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
  548.         push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
  549.         unless $prefix eq 'EXTRA_';
  550.         $source_list = $contents{$prefix . $one_file . "_SOURCES"};
  551.     }
  552.     elsif ($prefix eq '')
  553.     {
  554.         $output_vars .= $one_file . "_SOURCES = " . $unxformed . ".c\n";
  555.         push (@sources, $unxformed . '.c');
  556.         push (@objects, $unxformed . $obj);
  557.         $source_list = $unxformed . ".c ";
  558.     }
  559.     else
  560.     {
  561.         $output_vars .= "EXTRA_" . $one_file . "_SOURCES =\n";
  562.     }
  563.  
  564.     if ($source_list)
  565.     {
  566.         # Turn sources into objects.
  567.         local (@files) = split (' ', $source_list);
  568.         local (@result) = ();
  569.         foreach (@files)
  570.         {
  571.         # Skip header files, including C++-ish ones.
  572.         next if /\.[hH]$/;
  573.         next if /\.hxx$/;
  574.         # Skip things that look like macro references.
  575.         next if /^\$\(.*\)$/;
  576.         next if /^\$\{.*\}$/;
  577.         # Skip things that look like configure substitutions.
  578.         next if /^\@.*\@$/;
  579.  
  580.         if (/^(.*)\.[yl]$/)
  581.         {
  582.             # Automatically include generated .c file in
  583.             # distribution.
  584.             &push_dist_common ($1 . '.c');
  585.         }
  586.  
  587.         # Transform source files into .o files.
  588.         s/\.cc$/$obj/g;
  589.         s/\.cxx$/$obj/g;
  590.         s/\.[cCmylfs]$/$obj/g;
  591.         push (@result, $_)
  592.             unless $prefix eq 'EXTRA_';
  593.  
  594.         # Transform .o or $o file into .P file (for automatic
  595.         # dependency code).
  596.         s/$objpat$/.P/g;
  597.         $dep_files{'$(srcdir)/.deps/' . $_} = 1;
  598.         }
  599.  
  600.         &pretty_print ($one_file . "_OBJECTS =", "", @result)
  601.         unless $prefix eq 'EXTRA_';
  602.     }
  603.     }
  604.  
  605.     if (&variable_defined ('CONFIG_HEADER'))
  606.     {
  607.     $output_rules .= ('$(' . $one_file . "_OBJECTS): "
  608.               . $contents{'CONFIG_HEADER'} . "\n");
  609.     }
  610.  
  611.     return @result;
  612. }
  613.  
  614. # Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
  615. sub handle_lib_objects
  616. {
  617.     local ($var) = @_;
  618.  
  619.     die "programming error in handle_lib_objects"
  620.     if ! &variable_defined ($var);
  621.  
  622.     # We recognize certain things that are commonly put in LIBADD or
  623.     # LDADD.
  624.     local ($lsearch);
  625.  
  626.     foreach $lsearch (split (' ', $contents{$var}))
  627.     {
  628.     # Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
  629.     # means adding entries to dep_files.
  630.     if ($lsearch eq '@LIBOBJS@')
  631.     {
  632.         local ($iter, $rewrite);
  633.         foreach $iter (keys %libsources)
  634.         {
  635.         if ($iter ne 'alloca.c')
  636.         {
  637.             ($rewrite = $iter) =~ s/\.c$/.P/;
  638.             $dep_files{'$(srcdir)/.deps/' . $rewrite} = 1;
  639.             &require_file_with_line ($var, $FOREIGN, $iter);
  640.         }
  641.         }
  642.     }
  643.     elsif ($lsearch eq '@ALLOCA@')
  644.     {
  645.         &am_line_error ($var,
  646.                 "\@ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
  647.         if ! defined $libsources{'alloca.c'};
  648.         $dep_files{'$(srcdir)/.deps/alloca.P'} = 1;
  649.         &require_file_with_line ($var, $FOREIGN, 'alloca.c');
  650.     }
  651.     }
  652. }
  653.  
  654. # Handle C programs.
  655. sub handle_programs
  656. {
  657.     local (@proglist) = &am_install_var ('-clean',
  658.                      'programs', 'PROGRAMS',
  659.                      'bin', 'sbin', 'libexec', 'pkglib',
  660.                      'noinst', 'check');
  661.     return if ! @proglist;
  662.  
  663.     # If a program is installed, this is required.  We only want this
  664.     # error to appear once.
  665.     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
  666.     unless $seen_arg_prog;
  667.     $seen_arg_prog = 1;
  668.  
  669.     local ($obj) = &get_object_extension;
  670.     local ($one_file, $xname, $munge);
  671.  
  672.     foreach $one_file (@proglist)
  673.     {
  674.     # Canonicalize names.
  675.     ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
  676.     if ($xname ne $one_file)
  677.     {
  678.         local ($xt);
  679.         foreach $xt ('_LDADD', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
  680.         {
  681.         &am_line_error ($one_file . $xt,
  682.                 "invalid variable \`" . $one_file . $xt
  683.                 . "'; should be \`" . $xname . $xt . "'")
  684.             if &variable_defined ($one_file . $xt);
  685.         }
  686.     }
  687.  
  688.     &handle_source_transform ($xname, $one_file, $obj);
  689.  
  690.     if (&variable_defined ($xname . "_LDADD"))
  691.     {
  692.         &handle_lib_objects ($xname . '_LDADD');
  693.     }
  694.     else
  695.     {
  696.         # User didn't define prog_LDADD override.  So do it.
  697.         $output_vars .= $xname . '_LDADD = $(LDADD)' . "\n";
  698.     }
  699.  
  700.     $output_rules .=
  701.         &file_contents_with_transform
  702.         ('s/\@PROGRAM\@/' . $one_file . '/go;'
  703.          . 's/\@XPROGRAM\@/' . $xname . '/go;',
  704.          'program');
  705.     }
  706.  
  707.     &handle_lib_objects ('LDADD')
  708.     if &variable_defined ('LDADD');
  709. }
  710.  
  711. # Handle libraries.
  712. sub handle_libraries
  713. {
  714.     local (@liblist) = &am_install_var ('-no-all', '-clean',
  715.                     'libraries', 'LIBRARIES',
  716.                     'lib', 'pkglib', 'noinst', 'check');
  717.     return if ! @liblist;
  718.  
  719.     if (! $seen_ranlib)
  720.     {
  721.     # FIXME need am_line_error here.  But we don't know which
  722.     # variable exists.  Must add a loop...  No.  Must have
  723.     # am_install_var return a hash.  Otherwise the user could add
  724.     # install directories that we'd never find.
  725.     &am_error ("library requires either \`AC_PROG_RANLIB' or `gm_PROG_LIBTOOL' in configure.in");
  726.     # Only get this error once.
  727.     $seen_ranlib = 1;
  728.     }
  729.  
  730.     # Generate _LIBFILES variables.  Too bad we can't do this in
  731.     # am_install_var.
  732.     local ($onedir, $onelib);
  733.     local (@outlist);
  734.     foreach $onedir ('lib', 'pkglib', 'noinst', 'check')
  735.     {
  736.     if (&variable_defined ($onedir . '_LIBRARIES'))
  737.     {
  738.         @outlist = ();
  739.         foreach $onelib (split (' ', $contents{$onedir . '_LIBRARIES'}))
  740.         {
  741.         push (@outlist, 'lib' . $onelib . '.a');
  742.         }
  743.         &pretty_print ($onedir . '_LIBFILES =', "", @outlist);
  744.     }
  745.     }
  746.     push (@all, '$(LIBFILES)');
  747.  
  748.     local ($obj) = &get_object_extension;
  749.     local ($munge);
  750.     foreach $onelib (@liblist)
  751.     {
  752.     if (&variable_defined ($onelib . '_LIBADD'))
  753.     {
  754.         &handle_lib_objects ($onelib . '_LIBADD');
  755.     }
  756.     else
  757.     {
  758.         # Generate support for conditional object inclusion in
  759.         # libraries.
  760.         $output_vars .= $onelib . "_LIBADD =\n";
  761.     }
  762.  
  763.     &handle_source_transform ($onelib, $onelib, $obj);
  764.  
  765.     $output_rules .=
  766.         &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go',
  767.                        'library');
  768.     }
  769.  
  770.     # Turn "foo" into "libfoo.a" and include macro definition.
  771.     grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);
  772.  
  773.     if (! &variable_defined ('LIBFILES'))
  774.     {
  775.     &pretty_print ('LIBFILES = ', "", @liblist);
  776.     }
  777.  
  778.     if ($seen_libtool)
  779.     {
  780.     $output_vars .= ('AR = $(LIBTOOL) archive' . "\n"
  781.              . 'RANLIB = $(LIBTOOL) ranlib' . "\n"
  782.              . 'LCOMPILE = $(LIBTOOL) compile $(DEFS) $(INCLUDES)'
  783.              . ' $(CPPFLAGS) $(CFLAGS)' . "\n");
  784.     }
  785.     else
  786.     {
  787.     $output_vars .= ('AR = ar' . "\n"
  788.              . 'RANLIB = @RANLIB@' . "\n");
  789.     }
  790. }
  791.  
  792. # Handle scripts.
  793. sub handle_scripts
  794. {
  795.     # NOTE we no longer automatically clean SCRIPTS, because it is
  796.     # useful to sometimes distribute scripts verbatim.  This happens
  797.     # eg in Automake itself.
  798.     local ($msi);
  799.     $msi = &am_install_var ('scripts', 'SCRIPTS',
  800.                 'bin', 'sbin', 'libexec', 'pkgdata',
  801.                 'noinst', 'check');
  802.  
  803.     # We really only want a boolean value.
  804.     $scripts_installed = 1 if $msi;
  805.  
  806.     if ($scripts_installed)
  807.     {
  808.     # If a program is installed, this is required.  We only want this
  809.     # error to appear once.
  810.     &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
  811.         unless $seen_arg_prog;
  812.     $seen_arg_prog = 1;
  813.     }
  814. }
  815.  
  816. # Search a file for a "version.texi" Texinfo include.  Return the name
  817. # of the include file if found, or the empty string if not.  A
  818. # "version.texi" file is actually any file whose name matches
  819. # "vers*.texi".
  820. sub grep_for_vers_texi
  821. {
  822.     local ($filename) = @_;
  823.  
  824.     if (! open (TEXI, $filename))
  825.     {
  826.     &am_error ("couldn't open \`$filename': $!");
  827.     return '';
  828.     }
  829.     print "automake: reading $filename\n" if $verbose;
  830.  
  831.     while (<TEXI>)
  832.     {
  833.     if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
  834.     {
  835.         # Found it.
  836.         close (TEXI);
  837.         return $1;
  838.     }
  839.     }
  840.  
  841.     close (TEXI);
  842.     return '';
  843. }
  844.  
  845. # Handle all Texinfo source.
  846. sub handle_texinfo
  847. {
  848.     &am_line_error ('TEXINFOS',
  849.             "\`TEXINFOS' is an anachronism; use \`info_TEXINFOS'")
  850.     if &variable_defined ('TEXINFOS');
  851.     return if (! &variable_defined ('info_TEXINFOS')
  852.            && ! &variable_defined ('html_TEXINFOS'));
  853.  
  854.     local (@texis) = split (' ', $contents{'info_TEXINFOS'});
  855.  
  856.     local (@infos_list, @info_deps_list, @dvis_list, @texi_deps);
  857.     local ($infobase, $info_cursor);
  858.     local (%versions);
  859.     local ($done) = 0;
  860.     local ($vti);
  861.     local ($tc_cursor, @texi_cleans);
  862.     local ($canonical);
  863.  
  864.     foreach $info_cursor (@texis)
  865.     {
  866.     ($infobase = $info_cursor) =~ s/\.texi$//;
  867.  
  868.     # If 'version.texi' is referenced by input file, then include
  869.     # automatic versioning capability.
  870.     local ($vtexi)
  871.         = &grep_for_vers_texi ($relative_dir . "/" . $info_cursor);
  872.     if ($vtexi)
  873.     {
  874.         &am_error ("\`$vtexi', included in \`$info_cursor', also included in \`$versions{$vtexi}'")
  875.         if (defined $versions{$vtexi});
  876.         $versions{$vtexi} = $info_cursor;
  877.  
  878.         # We number the stamp-vti files.  This is doable since the
  879.         # actual names don't matter much.  We only number starting
  880.         # with the second one, so that the common case looks nice.
  881.         $vti = 'vti' . ($done ? $done : '');
  882.         &push_dist_common ($vtexi, 'stamp-' . $vti);
  883.         push (@clean, $vti);
  884.  
  885.         # Only require once.
  886.         &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
  887.                       'mdate-sh')
  888.         if ! $done;
  889.         ++$done;
  890.  
  891.         local ($conf_pat);
  892.         ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
  893.         $output_rules .=
  894.         &file_contents_with_transform
  895.             ('s/\@TEXI\@/' . $info_cursor . '/g; '
  896.              . 's/\@VTI\@/' . $vti . '/g; '
  897.              . 's/\@VTEXI\@/' . $vtexi . '/g;'
  898.              . 's,\@MDDIR\@,' . $conf_pat . ',g;',
  899.              'texi-version');
  900.  
  901.         &push_phony_cleaners ($vti);
  902.     }
  903.  
  904.     # If user specified file_TEXINFOS, then use that as explicit
  905.     # dependency list.
  906.     @texi_deps = ();
  907.     push (@texi_deps, $info_cursor);
  908.     push (@texi_deps, $vtexi) if $vtexi;
  909.  
  910.     # Canonicalize name first.
  911.     ($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
  912.     if (&variable_defined ($canonical . "_TEXINFOS"))
  913.     {
  914.         push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
  915.         &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
  916.     }
  917.  
  918.     $output_rules .= ("\n" . $infobase . ".info: "
  919.               . join (' ', @texi_deps) . "\n\n");
  920.  
  921.     push (@infos_list, $infobase . '.info*');
  922.     push (@info_deps_list, $infobase . '.info');
  923.     push (@dvis_list, $infobase . '.dvi');
  924.  
  925.     # Generate list of things to clean for this target.  We do
  926.     # this explicitly because otherwise too many things could be
  927.     # removed.  In particular the ".log" extension might
  928.     # reasonably be used in other contexts by the user.
  929.     foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
  930.                 'ky', 'log', 'pg', 'toc', 'tp', 'vr', 'op')
  931.     {
  932.         push (@texi_cleans, $infobase . '.' . $tc_cursor);
  933.     }
  934.     }
  935.  
  936.     # Some boilerplate.
  937.     $output_vars .= &file_contents ('texinfos-vars');
  938.     $output_rules .= &file_contents ('texinfos');
  939.     push (@phony, 'install-info', 'uninstall-info');
  940.  
  941.     # How to clean.
  942.     $output_rules .= "\nmostlyclean-info:\n";
  943.     &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
  944.     $output_rules .= ("\nclean-info:\n\ndistclean-info:\n\n"
  945.               . "maintainer-clean-info:\n\t"
  946.               . 'rm -f $(INFOS)' . "\n");
  947.     &push_phony_cleaners ('info');
  948.  
  949.     push (@suffixes, '.texi', '.info', '.dvi');
  950.     push (@uninstall, 'uninstall-info');
  951.     push (@clean, 'info');
  952.     push (@info, '$(INFO_DEPS)');
  953.     push (@dvi, '$(DVIS)');
  954.     push (@installdirs, '$(infodir)');
  955.     unshift (@install_data, 'install-info');
  956.  
  957.     # Make sure documentation is made and installed first.  Use
  958.     # $(INFO_DEPS), not 'info', because otherwise recursive makes get
  959.     # run twice during "make all".
  960.     unshift (@all, '$(INFO_DEPS)');
  961.  
  962.     $output_vars .= ("INFOS = " . join (' ', @infos_list) . "\n"
  963.              . "INFO_DEPS = " . join (' ', @info_deps_list)  . "\n"
  964.              . "DVIS = " . join (' ', @dvis_list) . "\n"
  965.              # This next isn't strictly needed now -- the
  966.              # places that look here could easily be changed
  967.              # to look in info_TEXINFOS.  But this is probably
  968.              # better, in case noinst_TEXINFOS is ever
  969.              # supported.
  970.              . "TEXINFOS = " . $contents{'info_TEXINFOS'} . "\n\n");
  971.  
  972.     # Do some error checking.
  973.     &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
  974. }
  975.  
  976. # Handle any man pages.
  977. sub handle_man_pages
  978. {
  979.     &am_line_error ('MANS', "\`MANS' is an anachronism; use \`man_MANS'")
  980.     if &variable_defined ('MANS');
  981.     return if ! &variable_defined ('man_MANS');
  982.  
  983.     # We generate the manpage install code by hand to avoid the use of
  984.     # basename in the generated Makefile.
  985.     local (@mans) = split (' ', $contents{'man_MANS'});
  986.     local (%sections, %inames, %secmap, %fullsecmap);
  987.     foreach (@mans)
  988.     {
  989.     # FIXME: statement without effect:
  990.     /^(.*)\.([0-9])([a-z]*)$/;
  991.     $sections{$2} = 1;
  992.     $inames{$1} = $_;
  993.     $secmap{$1} = $2;
  994.     $fullsecmap{$1} = $2 . $3;
  995.     }
  996.  
  997.     # We don't really need this, but we use it in case we ever want to
  998.     # support noinst_MANS.
  999.     $output_vars .= "MANS = " . $contents{'man_MANS'} . "\n";
  1000.  
  1001.     # Generate list of install dirs.
  1002.     $output_rules .= "install-man: \$(MANS)\n";
  1003.     foreach (keys %sections)
  1004.     {
  1005.     push (@installdirs, '$(mandir)/man' . $_);
  1006.     $output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
  1007.               . $_ . "\n");
  1008.     }
  1009.     push (@phony, 'install-man');
  1010.  
  1011.     # Generate install target.
  1012.     local ($key);
  1013.     foreach $key (keys %inames)
  1014.     {
  1015.     $_ = $install_man_format;
  1016.     s/\@SECTION\@/$secmap{$key}/g;
  1017.     s/\@MAN\@/$inames{$key}/g;
  1018.     s/\@FULLSECT\@/$fullsecmap{$key}/g;
  1019.     s/\@MANBASE\@/$key/g;
  1020.     $output_rules .= $_;
  1021.     }
  1022.     $output_rules .= "\n";
  1023.  
  1024.     $output_rules .= "uninstall-man:\n";
  1025.     foreach $key (keys %inames)
  1026.     {
  1027.     $_ = $uninstall_man_format;
  1028.     s/\@SECTION\@/$secmap{$key}/g;
  1029.     s/\@MAN\@/$inames{$key}/g;
  1030.     s/\@FULLSECT\@/$fullsecmap{$key}/g;
  1031.     s/\@MANBASE\@/$key/g;
  1032.     $output_rules .= $_;
  1033.     }
  1034.     $output_rules .= "\n";
  1035.     push (@phony, 'uninstall-man');
  1036.  
  1037.     $output_vars .= &file_contents ('mans-vars');
  1038.  
  1039.     if (! defined $options{'no-installman'})
  1040.     {
  1041.     push (@install_data, 'install-man');
  1042.     push (@uninstall, 'uninstall-man');
  1043.     push (@all, '$(MANS)');
  1044.     }
  1045. }
  1046.  
  1047. # Handle DATA variables.
  1048. sub handle_data
  1049. {
  1050.     &am_install_var ('data', 'DATA', 'data', 'sysconf',
  1051.              'sharedstate', 'localstate', 'pkgdata',
  1052.              'noinst', 'check');
  1053. }
  1054.  
  1055. # Handle TAGS.
  1056. sub handle_tags
  1057. {
  1058.     local ($tagging) = 0;
  1059.  
  1060.     push (@phony, 'tags');
  1061.     if (&variable_defined ('SUBDIRS'))
  1062.     {
  1063.     $output_rules .= &file_contents ('tags');
  1064.     push (@phony, 'tags-recursive');
  1065.     $tagging = 1;
  1066.     }
  1067.     elsif ($dir_holds_sources || &variable_defined ('ETAGS_ARGS'))
  1068.     {
  1069.     $output_rules .= &file_contents ('tags-subd');
  1070.     $tagging = 1;
  1071.     }
  1072.  
  1073.     if ($tagging)
  1074.     {
  1075.     $output_rules .= &file_contents ('tags-clean');
  1076.     push (@clean, 'tags');
  1077.     &push_phony_cleaners ('tags');
  1078.     }
  1079.     else
  1080.     {
  1081.     # Every Makefile must define some sort of TAGS rule.
  1082.     # Otherwise, it would be possible for a top-level "make TAGS"
  1083.     # to fail because some subdirectory failed.
  1084.     $output_rules .= "tags: TAGS\nTAGS:\n\n";
  1085.     }
  1086. }
  1087.  
  1088. # Worker for handle_dist.
  1089. sub handle_dist_worker
  1090. {
  1091.     $output_rules .= 'distdir: $(DEP_DISTFILES)' . "\n";
  1092.  
  1093.     # Initialization; only at top level.
  1094.     if ($relative_dir eq '.')
  1095.     {
  1096.     if ($strictness >= $GNITS)
  1097.     {
  1098.         # For Gnits users, this is pretty handy.  Look at 15 lines
  1099.         # in case some explanatory text is desirable.
  1100.         $output_rules .= '    @if sed 15q $(srcdir)/NEWS | grep -e "$(VERSION)" > /dev/null; then :; else \\
  1101.       echo "NEWS not updated; not releasing" 1>&2; \\
  1102.       exit 1;                \\
  1103.     fi
  1104. ';
  1105.     }
  1106.  
  1107.  
  1108.     $output_rules .=
  1109.         # Create dist directory.
  1110.         '    rm -rf $(distdir)
  1111.     mkdir $(distdir)
  1112.     chmod 777 $(distdir)
  1113. ';
  1114.  
  1115.     # Only run automake in `dist' target if --include-deps not
  1116.     # specified.  That way the recipient of a distribution can run
  1117.     # "make dist" and not need Automake.
  1118.     if ($cmdline_use_dependencies)
  1119.     {
  1120.         $output_rules .=
  1121.         (
  1122.          # We need an absolute path for --output-dir.  Thus the
  1123.          # weirdness.
  1124.          '    distdir=`cd $(distdir) && pwd` \\
  1125.       && cd $(srcdir) \\
  1126.       && automake --include-deps --output-dir=$$distdir --strictness='
  1127.          # Set strictness of output.
  1128.          . $strictness_name . "\n"
  1129.          );
  1130.     }
  1131.     }
  1132.  
  1133.     # In loop, test for file existence because sometimes a file gets
  1134.     # included in DISTFILES twice.  For example this happens when a
  1135.     # single source file is used in building more than one program.
  1136.     # Also, there are situations in which "ln" can fail.  For instance
  1137.     # a file to distribute could actually be a cross-filesystem
  1138.     # symlink -- this can easily happen if "gettextize" was run on the
  1139.     # distribution.  Note that DISTFILES can contain a wildcard (for
  1140.     # info files, sigh), so we must use the echo trick.
  1141.     $output_rules .= '    @for file in `cd $(srcdir) && echo $(DISTFILES)`; do \\
  1142.       test -f $(distdir)/$$file \\
  1143.       || ln $(srcdir)/$$file $(distdir)/$$file 2> /dev/null \\
  1144.       || cp -p $(srcdir)/$$file $(distdir)/$$file; \\
  1145.     done
  1146. ';
  1147.  
  1148.     # If we have SUBDIRS, create all dist subdirectories and do
  1149.     # recursive build.
  1150.     if (&variable_defined ('SUBDIRS'))
  1151.     {
  1152.     # Test for directory existence here because previous automake
  1153.     # invocation might have created some directories.  Note that
  1154.     # we explicitly set distdir for the subdir make; that lets us
  1155.     # mix-n-match many automake-using packages into one large
  1156.     # package, and have "dist" at the top level do the right
  1157.     # thing.
  1158.     $output_rules .= '    for subdir in $(SUBDIRS); do        \\
  1159.       test -d $(distdir)/$$subdir        \\
  1160.       || mkdir $(distdir)/$$subdir        \\
  1161.       || exit 1;                \\
  1162.       chmod 777 $(distdir)/$$subdir;    \\
  1163.       (cd $$subdir && $(MAKE) distdir=../$(distdir)/$$subdir distdir) \\
  1164.         || exit 1; \\
  1165.     done
  1166. ';
  1167.     }
  1168.  
  1169.     # If the target `dist-hook' exists, run it now.  This allows
  1170.     # users to do random weird things to the distribution before it is
  1171.     # packaged up.
  1172.     if (defined $contents{'dist-hook'})
  1173.     {
  1174.     $output_rules .= "\t\$(MAKE) dist-hook\n";
  1175.     }
  1176.  
  1177.     push (@phony, 'distdir');
  1178. }
  1179.  
  1180. # Handle 'dist' target.
  1181. sub handle_dist
  1182. {
  1183.     # Set up maint_charset.
  1184.     $local_maint_charset = $contents{'MAINT_CHARSET'}
  1185.     if &variable_defined ('MAINT_CHARSET');
  1186.     $maint_charset = $local_maint_charset
  1187.     if $relative_dir eq '.';
  1188.  
  1189.     if (&variable_defined ('DIST_CHARSET'))
  1190.     {
  1191.     &am_line_error ('DIST_CHARSET',
  1192.             "DIST_CHARSET defined but no MAINT_CHARSET defined")
  1193.         if ! $local_maint_charset;
  1194.     if ($relative_dir eq '.')
  1195.     {
  1196.         $dist_charset = $contents{'DIST_CHARSET'}
  1197.     }
  1198.     else
  1199.     {
  1200.         &am_line_error ('DIST_CHARSET',
  1201.                 "DIST_CHARSET can only be defined at top level");
  1202.     }
  1203.     }
  1204.  
  1205.     # Look for common files that should be included in distribution.
  1206.     local ($cfile);
  1207.     foreach $cfile (@common_files)
  1208.     {
  1209.     if (-f ($relative_dir . "/" . $cfile))
  1210.     {
  1211.         &push_dist_common ($cfile);
  1212.     }
  1213.     }
  1214.  
  1215.     # Keys of %dist_common are names of files to distributed.  We put
  1216.     # README first because it then becomes easier to make a
  1217.     # Usenet-compliant shar file (in these, README must be first).
  1218.     # FIXME do more ordering of files here.
  1219.     local (@coms);
  1220.     if (defined $dist_common{'README'})
  1221.     {
  1222.     push (@coms, 'README');
  1223.     undef $dist_common{'README'};
  1224.     }
  1225.     push (@coms, sort keys %dist_common);
  1226.  
  1227.     &pretty_print ("DIST_COMMON =", "", @coms);
  1228.     $output_vars .= "\n";
  1229.  
  1230.     # Some boilerplate.
  1231.     $output_vars .= &file_contents ('dist-vars');
  1232.  
  1233.     # Put these things in rules section so it is easier for whoever
  1234.     # reads Makefile.in.
  1235.     if ($relative_dir eq '.')
  1236.     {
  1237.     $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
  1238.     }
  1239.     else
  1240.     {
  1241.     $output_rules .= ("\nsubdir = " . $relative_dir . "\n"
  1242.               . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
  1243.               . "\n");
  1244.     }
  1245.  
  1246.     # Generate 'dist' target, and maybe dist-shar / dist-zip.
  1247.     if ($relative_dir eq '.')
  1248.     {
  1249.     # Rule to check whether a distribution is viable.
  1250.     $output_rules .= '# This target untars the dist file and tries a VPATH configuration.  Then
  1251. # it guarantees that the distribution is self-contained by making another
  1252. # tarfile.
  1253. distcheck: dist
  1254.     rm -rf $(distdir)
  1255.     $(TAR) zxf $(distdir).tar.gz
  1256.     mkdir $(distdir)/=build
  1257.     mkdir $(distdir)/=inst
  1258.     dc_install_base=`cd $(distdir)/=inst && pwd`; \\
  1259.     cd $(distdir)/=build \\
  1260.       && ../configure --srcdir=.. --prefix=$$dc_install_base \\
  1261.       && $(MAKE) \\
  1262.       && $(MAKE) check \\
  1263.       && $(MAKE) install \\
  1264.       && $(MAKE) installcheck \\
  1265.       && $(MAKE) dist
  1266.     rm -rf $(distdir)
  1267.     @echo "========================"; \\
  1268.     echo "$(distdir).tar.gz is ready for distribution"; \\
  1269.     echo "========================"
  1270. ';
  1271.  
  1272.     $output_rules .= 'dist: distdir' . "\n\t";
  1273.     $output_rules .= 'chmod -R a+r $(distdir)' . "\n\t";
  1274.     $output_rules .= '$(TAR) chozf $(distdir).tar.gz $(distdir)';
  1275.     $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
  1276.  
  1277.     if (defined $options{'dist-shar'})
  1278.     {
  1279.         $output_rules .= 'dist-shar: distdir' . "\n\t";
  1280.         $output_rules .= 'chmod -R a+r $(distdir)' . "\n\t";
  1281.         $output_rules .= 'shar $(distdir) | gzip > $(distdir).shar.gz';
  1282.         $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
  1283.     }
  1284.  
  1285.     if (defined $options{'dist-zip'})
  1286.     {
  1287.         $output_rules .= 'dist-zip: distdir' . "\n\t";
  1288.         $output_rules .= 'chmod -R a+r $(distdir)' . "\n\t";
  1289.         $output_rules .= 'zip -rq $(distdir).zip $(distdir)';
  1290.         $output_rules .= "\n\t" . 'rm -rf $(distdir)' . "\n";
  1291.     }
  1292.     }
  1293.  
  1294.     # Generate distdir target.
  1295.     &handle_dist_worker;
  1296. }
  1297.  
  1298. # Handle auto-dependency code.
  1299. sub handle_dependencies
  1300. {
  1301.     if ($use_dependencies)
  1302.     {
  1303.     # Include GNU-make-specific auto-dep code.
  1304.     if ($dir_holds_sources)
  1305.     {
  1306.         &pretty_print ('DEP_FILES =', "", sort keys %dep_files);
  1307.         $output_rules .= &file_contents ('depend');
  1308.     }
  1309.     }
  1310.     else
  1311.     {
  1312.     # Include any auto-generated deps that are present.
  1313.     if (-d ($relative_dir . "/.deps") && -f ($relative_dir . "/.deps/.P"))
  1314.     {
  1315.         local ($depfile);
  1316.         local ($gpat) = $relative_dir . "/.deps/*.P";
  1317.  
  1318.         foreach $depfile (<${gpat}>)
  1319.         {
  1320.         if (! open (DEP_FILE, $depfile))
  1321.         {
  1322.             &am_error ("couldn't open \`$depfile': $!");
  1323.             next;
  1324.         }
  1325.         print "automake: reading $depfile\n" if $verbose;
  1326.  
  1327.         # Slurp entire file.
  1328.         $output_rules .= join ('', <DEP_FILE>);
  1329.  
  1330.         close (DEP_FILE);
  1331.         }
  1332.  
  1333.         $output_rules .= "\n";
  1334.     }
  1335.     }
  1336. }
  1337.  
  1338. # Handle subdirectories.
  1339. sub handle_subdirs
  1340. {
  1341.     if (! &variable_defined ('SUBDIRS'))
  1342.     {
  1343.     &am_conf_error
  1344.         ("ud_GNU_GETTEXT in configure.in but SUBDIRS not defined")
  1345.         if $seen_gettext && $relative_dir eq '.';
  1346.     return;
  1347.     }
  1348.  
  1349.     &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
  1350.     if $seen_gettext;
  1351.  
  1352.     return if ! &variable_defined ('SUBDIRS');
  1353.  
  1354.     # Make sure each directory mentioned in SUBDIRS actually exists.
  1355.     local ($dir);
  1356.     foreach $dir (split (' ', $contents{'SUBDIRS'}))
  1357.     {
  1358.     # Skip directories substituted by configure.
  1359.     next if $dir =~ /^\@.*\@$/;
  1360.     &am_line_error ('SUBDIRS',
  1361.             "required directory $relative_dir/$dir does not exist")
  1362.         if ! -d $relative_dir . '/' . $dir;
  1363.     }
  1364.  
  1365.     $output_rules .= &file_contents ('subdirs');
  1366.  
  1367.     # Push a bunch of phony targets.
  1368.     local ($phonies);
  1369.     foreach $phonies ('-data', '-exec', 'dirs')
  1370.     {
  1371.     push (@phony, 'install' . $phonies . '-recursive');
  1372.     push (@phony, 'uninstall' . $phonies . '-recursive');
  1373.     }
  1374.     foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
  1375.     {
  1376.     push (@phony, $phonies . '-recursive');
  1377.     }
  1378.     &push_phony_cleaners ('recursive');
  1379.  
  1380.     push (@check, "check-recursive");
  1381.     push (@installcheck, "installcheck-recursive");
  1382.     push (@info, "info-recursive");
  1383.     push (@dvi, "dvi-recursive");
  1384.  
  1385.     $recursive_install = 1;
  1386. }
  1387.  
  1388. # Handle remaking and configure stuff.
  1389. sub handle_configure
  1390. {
  1391.     # If SUBDIRS defined, require AC_PROG_MAKE_SET.
  1392.     &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
  1393.     if &variable_defined ('SUBDIRS') && ! $seen_make_set;
  1394.  
  1395.     local ($top_reldir);
  1396.     if ($relative_dir ne '.')
  1397.     {
  1398.     # In subdirectory.
  1399.     $output_rules .= &file_contents ('remake-subd');
  1400.     $top_reldir = '../';
  1401.     }
  1402.     else
  1403.     {
  1404.     if (-f 'aclocal.m4')
  1405.     {
  1406.         $output_vars .= "ACLOCAL = aclocal.m4\n";
  1407.         &push_dist_common ('aclocal.m4');
  1408.     }
  1409.     $output_rules .= &file_contents ('remake');
  1410.  
  1411.     &am_error
  1412.         ("\`install.sh' is an anachronism; use \`install-sh' instead")
  1413.         if -f $relative_dir . '/install.sh';
  1414.  
  1415.     # If we have a configure header, require it.
  1416.     if ($config_header)
  1417.     {
  1418.         # FIXME this restriction should be lifted.
  1419.         # FIXME first see if it is even needed as-is.
  1420.         &am_conf_line_error ($config_header_line,
  1421.                  "argument to AC_CONFIG_HEADER contains \`/'\n")
  1422.         if ($config_header =~ /\//);
  1423.  
  1424.         &require_file_with_conf_line ($config_header_line,
  1425.                       $FOREIGN, $config_header);
  1426.  
  1427.         # Header defined and in this directory.
  1428.         if (-f 'acconfig.h')
  1429.         {
  1430.         $output_vars .= "ACCONFIG = acconfig.h\n";
  1431.         &push_dist_common ('acconfig.h');
  1432.         }
  1433.         if (-f $config_name . '.top')
  1434.         {
  1435.         $output_vars .= "CONFIG_TOP = ${config_name}.top\n";
  1436.         &push_dist_common ($config_name . '.top');
  1437.         }
  1438.         if (-f $config_name . '.bot')
  1439.         {
  1440.         $output_vars .= "CONFIG_BOT = ${config_name}.bot\n";
  1441.         &push_dist_common ($config_name . '.bot');
  1442.         }
  1443.  
  1444.         &require_file_with_conf_line ($config_header_line, $FOREIGN,
  1445.                       'stamp-h.in');
  1446.  
  1447.         $output_rules .= &file_contents ('remake-hdr');
  1448.         $output_vars .= "CONFIG_HEADER_IN = ${config_header}\n";
  1449.     }
  1450.  
  1451.     $top_reldir = '';
  1452.     }
  1453.  
  1454.     # Set location of mkinstalldirs.
  1455.     if ($config_aux_dir ne '.' && $config_aux_dir ne '')
  1456.     {
  1457.     $output_vars .= 'mkinstalldirs = ' . $config_aux_dir;
  1458.     }
  1459.     else
  1460.     {
  1461.     $output_vars .= 'mkinstalldirs = $(top_srcdir)';
  1462.     }
  1463.     $output_vars .= '/mkinstalldirs' . "\n";
  1464.  
  1465.     &am_line_error ('CONFIG_HEADER',
  1466.             "\`CONFIG_HEADER' is an anachronism; now determined from \`configure.in'")
  1467.     if &variable_defined ('CONFIG_HEADER');
  1468.  
  1469.     # Generate CONFIG_HEADER define, and define interally.
  1470.     $output_vars .= "CONFIG_HEADER = ${top_builddir}/${config_name}\n"
  1471.     if $config_name;
  1472.     $contents{'CONFIG_HEADER'} = "${top_builddir}/${config_name}"
  1473.     if $config_name;
  1474.  
  1475.     # Now look for other files in this directory which must be remade
  1476.     # by config.status, and generate rules for them.
  1477.     local ($file, $local, $input);
  1478.     foreach $file (@other_input_files)
  1479.     {
  1480.     # Skip files not in this directory, any Makefile, and the
  1481.     # config header.  These last two must be handled specially.
  1482.     next unless &dirname ($file) eq $relative_dir;
  1483.     next if $file eq $top_builddir . '/' . $config_name;
  1484.     ($local = $file) =~ s/^.*\///;
  1485.     next if $local eq 'Makefile';
  1486.  
  1487.     if ($local =~ /^(.*):(.*)$/)
  1488.     {
  1489.         # This is the ":" syntax of AC_OUTPUT.
  1490.         $input = $2;
  1491.         $local = $1;
  1492.     }
  1493.     else
  1494.     {
  1495.         # Normal usage.
  1496.         $input = $local . '.in';
  1497.     }
  1498.     # FIXME when using autoconf ":" syntax, should we set CONFIG_FILES
  1499.     # to $local:$input?
  1500.     $output_rules .= ($local . ': '
  1501.               . '$(top_builddir)/config.status ' . $input . "\n"
  1502.               . "\t"
  1503.               . 'cd $(top_builddir) && CONFIG_FILES='
  1504.               . ($relative_dir eq '.' ? '' : '$(subdir)/')
  1505.               . '$@ CONFIG_HEADERS= ./config.status'
  1506.               . "\n");
  1507.  
  1508.     &require_file_with_conf_line ($ac_output_line, $FOREIGN,
  1509.                       $local . '.in');
  1510.     }
  1511. }
  1512.  
  1513. # Handle C headers.
  1514. sub handle_headers
  1515. {
  1516.     &am_install_var ('header', 'HEADERS', 'include',
  1517.              'oldinclude', 'pkginclude',
  1518.              'noinst', 'check');
  1519. }
  1520.  
  1521. sub handle_gettext
  1522. {
  1523.     return if ! $seen_gettext || $relative_dir ne '.';
  1524.  
  1525.     # As of 0.10.6, gettext still wants @INTLSUB@ and @POSUB@ in
  1526.     # SUBDIRS.  This is going to change in a future version.  So for
  1527.     # now we simply do no checking.
  1528.     if (0 && &variable_defined ('SUBDIRS'))
  1529.     {
  1530.     &am_line_error
  1531.         ('SUBDIRS',
  1532.          "ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
  1533.         if $contents{'SUBDIRS'} !~ /\bpo\b/;
  1534.     &am_line_error
  1535.         ('SUBDIRS',
  1536.          "ud_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
  1537.         if $contents{'SUBDIRS'} !~ /\bintl\b/;
  1538.     }
  1539.  
  1540.     # Ensure that each language in ALL_LINGUAS has a .po file, and
  1541.     # each po file is mentioned in ALL_LINGUAS.
  1542.     if ($seen_linguas)
  1543.     {
  1544.     local (%linguas) = ();
  1545.     grep ($linguas{$_} = 1, split (' ', $all_linguas));
  1546.  
  1547.     foreach (<po/*.po>)
  1548.     {
  1549.         s/^po\///;
  1550.         s/\.po$//;
  1551.  
  1552.         &am_line_error ($all_linguas_line,
  1553.                 ("po/$_.po exists but \`$_' not in \`ALL_LINGUAS'"))
  1554.         if ! $linguas{$_};
  1555.     }
  1556.  
  1557.     foreach (keys %linguas)
  1558.     {
  1559.         &am_line_error ($all_linguas_line,
  1560.                 "$_ in \`ALL_LINGUAS' but po/$_.po does not exist")
  1561.         if ! -f "po/$_.po";
  1562.     }
  1563.     }
  1564.     else
  1565.     {
  1566.     &am_error ("ud_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
  1567.     }
  1568. }
  1569.  
  1570. # Handle footer elements.
  1571. sub handle_footer
  1572. {
  1573.     if ($contents{'SOURCES'})
  1574.     {
  1575.     &pretty_print ('SOURCES =', "",
  1576.                split (' ', $contents{'SOURCES'}));
  1577.     }
  1578.     if ($contents{'OBJECTS'})
  1579.     {
  1580.     &pretty_print ('OBJECTS =', "",
  1581.                split (' ', $contents{'OBJECTS'}));
  1582.     }
  1583.     if ($contents{'SOURCES'} || $contents{'OBJECTS'})
  1584.     {
  1585.     $output_vars .= "\n";
  1586.     }
  1587.  
  1588.     if (defined $contents{'SUFFIXES'})
  1589.     {
  1590.     push (@suffixes, '$(SUFFIXES)');
  1591.     }
  1592.  
  1593.     $output_trailer .= ".SUFFIXES:\n";
  1594.     if (@suffixes)
  1595.     {
  1596.     $output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
  1597.     }
  1598.     $output_trailer .= &file_contents ('footer');
  1599. }
  1600.  
  1601. # Deal with installdirs target.
  1602. sub handle_installdirs
  1603. {
  1604.     # GNU Makefile standards recommend this.
  1605.     $output_rules .= ("installdirs:"
  1606.               . ($recursive_install
  1607.              ? " installdirs-recursive\n"
  1608.              : "\n"));
  1609.     push (@phony, 'installdirs');
  1610.     if (@installdirs)
  1611.     {
  1612.     &pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
  1613.                 @installdirs);
  1614.     }
  1615.     $output_rules .= "\n";
  1616. }
  1617.  
  1618. # There are several targets which need to be merged.  This is because
  1619. # their complete definition is compiled from many parts.  Note that we
  1620. # avoid double colon rules, otherwise we'd use them instead.
  1621. sub handle_merge_targets
  1622. {
  1623.     push (@all, 'Makefile');
  1624.     push (@all, $config_name)
  1625.     if $config_name && &dirname ($config_name) eq $relative_dir;
  1626.  
  1627.     &do_one_merge_target ('info', @info);
  1628.     &do_one_merge_target ('dvi', @dvi);
  1629.  
  1630.     if (! &variable_defined ('SUBDIRS') || $relative_dir ne '.')
  1631.     {
  1632.     # 'check' must depend on 'all', but not at top level.
  1633.     # Ditto install.
  1634.     unshift (@check, 'all');
  1635.     unshift (@install, 'all');
  1636.     }
  1637.     &do_one_merge_target ('check', @check);
  1638.     &do_one_merge_target ('installcheck', @installcheck);
  1639.  
  1640.     # Handle the various install targets specially.  We do this so
  1641.     # that (eg) "make install-exec" will run "install-exec-recursive"
  1642.     # if required, but "make install" won't run it twice.  Step one is
  1643.     # to see if the user specified local versions of any of the
  1644.     # targets we handle.  "all" is treated as one of these since
  1645.     # "install" can run it.
  1646.     push (@install_exec, 'install-exec-local')
  1647.     if defined $contents{'install-exec-local'};
  1648.     push (@install_data, 'install-data-local')
  1649.     if defined $contents{'install-data-local'};
  1650.     push (@uninstall, 'uninstall-local')
  1651.     if defined $contents{'uninstall-local'};
  1652.     push (@all, 'all-local')
  1653.     if defined $contents{'all-local'};
  1654.  
  1655.     if (defined $contents{'install-local'})
  1656.     {
  1657.     &am_line_error ('install-local',
  1658.             "use \`install-data' or \`install-exec', not \`install'");
  1659.     }
  1660.  
  1661.     # Step two: if we are doing recursive makes, write out the
  1662.     # appropriate rules.
  1663.     local (@install);
  1664.     if ($recursive_install)
  1665.     {
  1666.     push (@install, 'install-recursive');
  1667.  
  1668.     if (@all)
  1669.     {
  1670.         local (@hackall) = ();
  1671.         if ($config_name && &dirname ($config_name) eq $relative_dir)
  1672.         {
  1673.  
  1674.         # This is kind of a hack, but I couldn't see a better
  1675.         # way to handle it.  In this particular case, we need
  1676.         # to make sure config.h is built before we recurse.
  1677.         # We can't do this by changing the order of
  1678.         # dependencies to the "all" because that breaks when
  1679.         # using parallel makes.  Instead we handle things
  1680.         # explicitly.
  1681.         $output_rules .= ('all-recursive-hack: $(CONFIG_HEADER)'
  1682.                   . "\n\t" . '$(MAKE) all-recursive'
  1683.                   . "\n\n");
  1684.         push (@hackall, 'all-recursive-hack');
  1685.         push (@phony, 'all-recursive-hack');
  1686.         }
  1687.         else
  1688.         {
  1689.         push (@hackall, 'all-recursive');
  1690.         }
  1691.  
  1692.         $output_rules .= ('all-am: '
  1693.                   . join (' ', @all)
  1694.                   . "\n\n");
  1695.         @all = @hackall;
  1696.         push (@all, 'all-am');
  1697.         push (@phony, 'all-am');
  1698.     }
  1699.     else
  1700.     {
  1701.         @all = ('all-recursive');
  1702.     }
  1703.     if (@install_exec)
  1704.     {
  1705.         $output_rules .= ('install-exec-am: '
  1706.                   . join (' ', @install_exec)
  1707.                   . "\n\n");
  1708.         @install_exec = ('install-exec-recursive', 'install-exec-am');
  1709.         push (@install, 'install-exec-am');
  1710.         push (@phony, 'install-exec-am');
  1711.     }
  1712.     else
  1713.     {
  1714.         @install_exec = ('install-exec-recursive');
  1715.     }
  1716.     if (@install_data)
  1717.     {
  1718.         $output_rules .= ('install-data-am: '
  1719.                   . join (' ', @install_data)
  1720.                   . "\n\n");
  1721.         @install_data = ('install-data-recursive', 'install-data-am');
  1722.         push (@install, 'install-data-am');
  1723.         push (@phony, 'install-data-am');
  1724.     }
  1725.     else
  1726.     {
  1727.         @install_data = ('install-data-recursive');
  1728.     }
  1729.     if (@uninstall)
  1730.     {
  1731.         $output_rules .= ('uninstall-am: '
  1732.                   . join (' ', @uninstall)
  1733.                   . "\n\n");
  1734.         @uninstall = ('uninstall-recursive', 'uninstall-am');
  1735.         push (@phony, 'uninstall-am');
  1736.     }
  1737.     else
  1738.     {
  1739.         @uninstall = ('uninstall-recursive');
  1740.     }
  1741.     }
  1742.  
  1743.     # Step three: print definitions users can use.  Code below knows
  1744.     # that install-exec is done before install-data, beware.
  1745.     $output_rules .= ("install-exec: "
  1746.               . join (' ', @install_exec)
  1747.               . "\n");
  1748.     if (defined $contents{'install-exec-hook'})
  1749.     {
  1750.     $output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
  1751.     }
  1752.     $output_rules .= "\n";
  1753.     push (@install, 'install-exec') if !$recursive_install;
  1754.     push (@phony, 'install-exec');
  1755.  
  1756.     $output_rules .= ("install-data: "
  1757.               . join (' ', @install_data)
  1758.               . "\n");
  1759.     if (defined $contents{'install-data-hook'})
  1760.     {
  1761.     $output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
  1762.     }
  1763.     $output_rules .= "\n";
  1764.     push (@install, 'install-data') if !$recursive_install;
  1765.     push (@phony, 'install-data');
  1766.  
  1767.     # If no dependencies for 'install', add 'all'.  Why?  That way
  1768.     # "make install" at top level of distclean'd distribution won't
  1769.     # fail because stuff in 'lib' fails to build.
  1770.     if (! @install || ($#install == 1
  1771.                && $install[0] eq 'install-exec'
  1772.                && $install[1] eq 'install-data'))
  1773.     {
  1774.     push (@install, 'all');
  1775.     }
  1776.     $output_rules .= ('install: '
  1777.               . join (' ', @install)
  1778.               # Use "@:" as empty command so nothing prints.
  1779.               . "\n\t\@:"
  1780.               . "\n\n"
  1781.               . 'uninstall: '
  1782.               . join (' ', @uninstall)
  1783.               . "\n\n");
  1784.     push (@phony, 'install', 'uninstall');
  1785.  
  1786.     $output_rules .= ('all: '
  1787.               . join (' ', @all)
  1788.               . "\n\n");
  1789.     push (@phony, 'all');
  1790.  
  1791.     # Generate the new 'install-strip' target.
  1792.     $output_rules .= ("install-strip:\n\t"
  1793.               . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' install'
  1794.               . "\n");
  1795. }
  1796.  
  1797. # Helper for handle_merge_targets.
  1798. sub do_one_merge_target
  1799. {
  1800.     local ($name, @values) = @_;
  1801.  
  1802.     if (defined $contents{$name . '-local'})
  1803.     {
  1804.     # User defined local form of target.  So include it.
  1805.     push (@values, $name . '-local');
  1806.     push (@phony, $name . '-local');
  1807.     }
  1808.  
  1809.     $output_rules .= $name . ":";
  1810.     if (@values)
  1811.     {
  1812.     $output_rules .= ' ' . join (' ', @values);
  1813.     }
  1814.     $output_rules .= "\n\n";
  1815.     push (@phony, $name);
  1816. }
  1817.  
  1818. # Handle all 'clean' targets.
  1819. sub handle_clean
  1820. {
  1821.     push (@clean, 'generic');
  1822.     $output_rules .= &file_contents ('clean');
  1823.     &push_phony_cleaners ('generic');
  1824.  
  1825.     local ($target) = $recursive_install ? 'clean-am' : 'clean';
  1826.     &do_one_clean_target ($target, 'mostly', '', @clean);
  1827.     &do_one_clean_target ($target, '', 'mostly', @clean);
  1828.     &do_one_clean_target ($target, 'dist', '', @clean);
  1829.     &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);
  1830.  
  1831.     push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');
  1832.  
  1833.     local (@deps);
  1834.     if ($recursive_install)
  1835.     {
  1836.     @deps = ('am', 'recursive');
  1837.     &do_one_clean_target ('', 'mostly', '', @deps);
  1838.     &do_one_clean_target ('', '', '', @deps);
  1839.     &do_one_clean_target ('', 'dist', '', @deps);
  1840.     &do_one_clean_target ('', 'maintainer-', '', @deps);
  1841.     }
  1842. }
  1843.  
  1844. # Helper for handle_clean.
  1845. sub do_one_clean_target
  1846. {
  1847.     local ($target, $name, $last_name, @deps) = @_;
  1848.  
  1849.     # Special case: if target not passed, then don't generate
  1850.     # dependency on next "lower" clean target (eg no
  1851.     # clean<-mostlyclean derivation).  In this case the target is
  1852.     # implicitly known to be 'clean'.
  1853.     local ($flag) = $target;
  1854.     $target = 'clean' if ! $flag;
  1855.  
  1856.     grep (($_ = $name . 'clean-' . $_) && 0, @deps);
  1857.     if ($flag)
  1858.     {
  1859.     if ($last_name || $name ne 'mostly')
  1860.     {
  1861.         push (@deps, $last_name . $target . " ");
  1862.     }
  1863.     }
  1864.     # FIXME not sure if I like the tabs here.
  1865.     &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);
  1866.  
  1867.     # FIXME shouldn't we really print these messages before running
  1868.     # the dependencies?
  1869.     if ($name . $target eq 'maintainer-clean')
  1870.     {
  1871.     # Print a special warning.
  1872.     $output_rules .=
  1873.         ("\t\@echo \"This command is intended for maintainers to use;\"\n"
  1874.          . "\t\@echo \"it deletes files that may require special "
  1875.          . "tools to rebuild.\"\n");
  1876.  
  1877.     $output_rules .= "\trm -f config.status\n"
  1878.         if $relative_dir eq '.';
  1879.     }
  1880.     elsif ($name . $target eq 'distclean')
  1881.     {
  1882.     $output_rules .= "\trm -f config.status\n";
  1883.     }
  1884.     $output_rules .= "\n";
  1885. }
  1886.  
  1887. # Handle .PHONY target.
  1888. sub handle_phony
  1889. {
  1890.     &pretty_print_rule ('.PHONY:', "", @phony);
  1891.     $output_rules .= "\n";
  1892. }
  1893.  
  1894. # Handle TESTS variable and other checks.
  1895. sub handle_tests
  1896. {
  1897.     if (&variable_defined ('DEJATOOL') && ! defined $options{'dejagnu'})
  1898.     {
  1899.     # Error.
  1900.     &am_line_error ('DEJATOOL',
  1901.             "\`DEJATOOL' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
  1902.     return;
  1903.     }
  1904.  
  1905.     if (defined $options{'dejagnu'})
  1906.     {
  1907.     push (@check, 'check-DEJAGNU');
  1908.     push (@phony, 'check-DEJAGNU');
  1909.     $output_rules .= &file_contents ('dejagnu');
  1910.     }
  1911.     elsif (&variable_defined ('TESTS'))
  1912.     {
  1913.     push (@check, 'check-TESTS');
  1914.     push (@phony, 'check-TESTS');
  1915.     # FIXME use $(SHELL) here?  That is what Ulrich suggests.
  1916.     # Maybe a new macro, $(TEST_SHELL), a la $(CONFIG_SHELL)?  For
  1917.     # now we just execute the file directly; this allows test
  1918.     # files which are compiled -- a possibly useful feature.
  1919.     $output_rules .= 'check-TESTS: $(TESTS)
  1920.     @failed=0; all=0; \\
  1921.     srcdir=$(srcdir); export srcdir; \\
  1922.     for tst in $(TESTS); do \\
  1923.       all=`expr $$all + 1`; \\
  1924.       if test -f $$tst; then dir=.; \\
  1925.       else dir="$(srcdir)"; fi; \\
  1926.       if $$dir/$$tst; then \\
  1927.         echo "PASS: $$tst"; \\
  1928.       else \\
  1929.         failed=`expr $$failed + 1`; \\
  1930.         echo "FAIL: $$tst"; \\
  1931.       fi; \\
  1932.     done; \\
  1933.     if test "$$failed" -eq 0; then \\
  1934.       echo "========================"; \\
  1935.       echo "All $$all tests passed"; \\
  1936.       echo "========================"; \\
  1937.     else \\
  1938.       echo "$$failed of $$all tests failed"; \\
  1939.     fi
  1940. ';
  1941.     }
  1942. }
  1943.  
  1944. ################################################################
  1945.  
  1946. # Scan configure.in for interesting things.
  1947. # FIXME ensure VERSION, PACKAGE are set.
  1948. sub scan_configure
  1949. {
  1950.     open (CONFIGURE, 'configure.in')
  1951.     || die "automake: couldn't open \`configure.in': $!\n";
  1952.     print "automake: reading configure.in\n" if $verbose;
  1953.  
  1954.     # Reinitialize libsources here.  This isn't really necessary,
  1955.     # since we currently assume there is only one configure.in.  But
  1956.     # that won't always be the case.
  1957.     %libsources = ();
  1958.  
  1959.     local ($in_ac_output, @make_list) = 0;
  1960.     local ($libobj_iter);
  1961.     while (<CONFIGURE>)
  1962.     {
  1963.     # Remove comments from current line.
  1964.     s/\bdnl\b.*$//;
  1965.     s/\#.*$//;
  1966.  
  1967.     # Populate libobjs array.
  1968.     if (/AC_FUNC_ALLOCA/)
  1969.     {
  1970.         $libsources{'alloca.c'} = 1;
  1971.     }
  1972.     elsif (/AC_FUNC_GETLOADAVG/)
  1973.     {
  1974.         $libsources{'getloadavg.c'} = 1;
  1975.     }
  1976.     elsif (/AC_FUNC_MEMCMP/)
  1977.     {
  1978.         $libsources{'memcmp.c'} = 1;
  1979.     }
  1980.     elsif (/AC_STRUCT_ST_BLOCKS/)
  1981.     {
  1982.         $libsources{'fileblocks.c'} = 1;
  1983.     }
  1984.     elsif (/(AC|fp)_FUNC_FNMATCH/)
  1985.     {
  1986.         # AC_FUNC_FNMATCH is just wishful thinking at this point.
  1987.         $libsources{'fnmatch.c'} = 1;
  1988.     }
  1989.     elsif (/AC_REPLACE_FUNCS\s*\((.*)\)/)
  1990.     {
  1991.         foreach (split (' ', $1))
  1992.         {
  1993.         $libsources{$_ . '.c'} = 1;
  1994.         }
  1995.     }
  1996.     elsif (/AC_REPLACE_GNU_GETOPT/)
  1997.     {
  1998.         $libsources{'getopt.c'} = 1;
  1999.         $libsources{'getopt1.c'} = 1;
  2000.     }
  2001.     elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
  2002.            || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
  2003.     {
  2004.         foreach $libobj_iter (split (' ', $1))
  2005.         {
  2006.         if ($libobj_iter =~ /^(.*)\.o$/)
  2007.         {
  2008.             $libsources{$1 . '.c'} = 1;
  2009.         }
  2010.         }
  2011.     }
  2012.  
  2013.     # Process the AC_OUTPUT macro.
  2014.     if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
  2015.     {
  2016.         $in_ac_output = 1;
  2017.         $ac_output_line = $.;
  2018.     }
  2019.     if ($in_ac_output)
  2020.     {
  2021.         $in_ac_output = 0 if s/[\]\),].*$//;
  2022.  
  2023.         # Look at potential Makefile.am's.
  2024.         foreach (split)
  2025.         {
  2026.         next if $_ eq "\\";
  2027.         if (-f $_ . '.am')
  2028.         {
  2029.             push (@make_list, $_);
  2030.         }
  2031.         else
  2032.         {
  2033.             push (@other_input_files, $_);
  2034.         }
  2035.         }
  2036.     }
  2037.  
  2038.     if (/AC_CONFIG_AUX_DIR\(([^)]+)\)/)
  2039.     {
  2040.         @config_aux_path = $1;
  2041.     }
  2042.  
  2043.     # Check for ansi2knr.
  2044.     $fp_c_prototypes = 1 if /fp_C_PROTOTYPES/;
  2045.  
  2046.     # Check for NLS support.
  2047.     if (/ud_GNU_GETTEXT/)
  2048.     {
  2049.         $seen_gettext = 1;
  2050.         $ac_gettext_line = $.;
  2051.     }
  2052.  
  2053.         # Look for ALL_LINGUAS.
  2054.         if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
  2055.     {
  2056.         $seen_linguas = 1;
  2057.         $all_linguas = $1;
  2058.         $all_linguas_line = $.;
  2059.     }
  2060.  
  2061.     # Handle configuration headers.
  2062.     if (/AC_CONFIG_HEADER\s*\((.*)\)/)
  2063.     {
  2064.         $config_header_line = $.;
  2065.         $config_name = $1;
  2066.         if ($config_name =~ /^([^:]+):(.+)$/)
  2067.         {
  2068.         $config_name = $1;
  2069.         $config_header = $2;
  2070.         }
  2071.         else
  2072.         {
  2073.         $config_header = $config_name . '.in';
  2074.         }
  2075.     }
  2076.  
  2077.     $seen_canonical = 1 if /AC_CANONICAL_(HOST|SYSTEM)/;
  2078.     $seen_canonical = 1 if /AC_CHECK_TOOL/;
  2079.     $seen_path_xtra = 1 if /AC_PATH_XTRA/;
  2080.  
  2081.     # Sometimes it is desirable to explicitly set YACC.  For
  2082.     # instance some people don't want to use bison.
  2083.     $seen_prog_yacc = 1 if (/AC_PROG_YACC/
  2084.                 || /AC_SUBST\(YACC\)/
  2085.                 || /AC_(PATH|CHECK)_PROGS?\(YACC/);
  2086.  
  2087.     # Some things required by Automake.
  2088.     $seen_make_set = 1 if /AC_PROG_MAKE_SET/;
  2089.     $seen_arg_prog = 1 if /AC_ARG_PROGRAM/;
  2090.     $seen_ranlib = 1 if /AC_PROG_RANLIB/;
  2091.         $seen_maint_mode = 1 if /jm_MAINTAINER_MODE/;
  2092.         $seen_package = 1 if /PACKAGE=/;
  2093.         $seen_version = 1 if /VERSION=/;        
  2094.  
  2095.         # Weird conditionals here because it is always allowed to
  2096.         # upgrade to fp_PROG_INSTALL but never to downgrade to
  2097.         # AC_PROG_INSTALL.
  2098.     $seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
  2099.     $seen_prog_install = 2 if /fp_PROG_INSTALL/;
  2100.  
  2101.         if (/AC_PROG_LIBTOOL/ || /gm_PROG_LIBTOOL/)
  2102.     {
  2103.         $seen_libtool = 1;
  2104.         $seen_ranlib = 2;
  2105.         $libtool_line = $.;
  2106.     }
  2107.     }
  2108.  
  2109.     # Set input files if not specified by user.
  2110.     @input_files = @make_list if (! @input_files);
  2111.  
  2112.     close (CONFIGURE);
  2113.  
  2114.     &am_conf_error ("\`PACKAGE' not defined in configure.in")
  2115.         if ! $seen_package;
  2116.     &am_conf_error ("\`VERSION' not defined in configure.in")
  2117.         if ! $seen_version;
  2118.  
  2119.     # Look for some files we need.  Always check for these.  This
  2120.     # check must be done for every run, even those where we are only
  2121.     # looking at a subdir Makefile.  We must set relative_dir so that
  2122.     # the file-finding machinery works.
  2123.     local ($relative_dir) = '.';
  2124.     &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs');
  2125. }
  2126.  
  2127. ################################################################
  2128.  
  2129. # Do any extra checking for GNU standards.
  2130. sub check_gnu_standards
  2131. {
  2132.     if ($relative_dir eq '.')
  2133.     {
  2134.     # In top level (or only) directory.
  2135.     &require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
  2136.                'AUTHORS', 'ChangeLog');
  2137.     }
  2138. }
  2139.  
  2140. # Do any extra checking for GNITS standards.
  2141. sub check_gnits_standards
  2142. {
  2143.     if ($strictness >= $GNITS && -f $relative_dir . '/COPYING.LIB')
  2144.     {
  2145.     &am_error
  2146.         ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
  2147.     }
  2148.  
  2149.     if ($relative_dir eq '.')
  2150.     {
  2151.     # In top level (or only) directory.
  2152.     &require_file ($GNITS, 'THANKS');
  2153.     }
  2154. }
  2155.  
  2156. ################################################################
  2157.  
  2158. # Pretty-print something.  HEAD is what should be printed at the
  2159. # beginning of the first line, FILL is what should be printed at the
  2160. # beginning of every subsequent line.
  2161. sub pretty_print_internal
  2162. {
  2163.     local ($head, $fill, @values) = @_;
  2164.  
  2165.     local ($column) = length ($head);
  2166.     local ($result) = $head;
  2167.  
  2168.     # Fill length is number of characters.  However, each Tab
  2169.     # character counts for eight.  So we count the number of Tabs and
  2170.     # multiply by 7.
  2171.     local ($fill_length) = length ($fill);
  2172.     $fill_length += 7 * ($fill =~ tr/\t/\t/d);
  2173.  
  2174.     local ($bol) = 0;
  2175.     foreach (@values)
  2176.     {
  2177.     # "71" because we also print a space.
  2178.     if ($column + length ($_) > 71)
  2179.     {
  2180.         $result .= " \\\n" . $fill;
  2181.         $column = $fill_length;
  2182.         $bol = 1;
  2183.     }
  2184.  
  2185.     $result .= ' ' unless ($bol);
  2186.     $result .= $_;
  2187.     $column += length ($_) + 1;
  2188.     $bol = 0;
  2189.     }
  2190.  
  2191.     $result .= "\n";
  2192.     return $result;
  2193. }
  2194.  
  2195. # Pretty-print something and append to output_vars.
  2196. sub pretty_print
  2197. {
  2198.     $output_vars .= &pretty_print_internal (@_);
  2199. }
  2200.  
  2201. # Pretty-print something and append to output_rules.
  2202. sub pretty_print_rule
  2203. {
  2204.     $output_rules .= &pretty_print_internal (@_);
  2205. }
  2206.  
  2207.  
  2208. ################################################################
  2209.  
  2210. # See if a variable exists.
  2211. sub variable_defined
  2212. {
  2213.     local ($var) = @_;
  2214.     if (defined $targets{$var})
  2215.     {
  2216.     &am_line_error ($var, "\`$var' is target; expected variable");
  2217.     }
  2218.     return (defined $contents{$var} && ! defined $targets{$var});
  2219. }
  2220.  
  2221. # Read Makefile.am and set up %contents.  Simultaneously copy lines
  2222. # from Makefile.am into $output_trailer or $output_vars as
  2223. # appropriate.  NOTE we put rules in the trailer section.  We want
  2224. # user rules to come after our generated stuff.
  2225. sub read_am_file
  2226. {
  2227.     local ($amfile) = @_;
  2228.  
  2229.     # Compute relative location of the top object directory.
  2230.     local (@topdir) = ();
  2231.     foreach (split (/\//, $relative_dir))
  2232.     {
  2233.     next if $_ eq '.' || $_ eq '';
  2234.     if ($_ eq '..')
  2235.     {
  2236.         pop @topdir;
  2237.     }
  2238.     else
  2239.     {
  2240.         push (@topdir, '..');
  2241.     }
  2242.     }
  2243.     @topdir = ('.') if ! @topdir;
  2244.  
  2245.     $top_builddir = join ('/', @topdir);
  2246.     local ($build_rx);
  2247.     ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
  2248.     local ($header_vars) =
  2249.     &file_contents_with_transform
  2250.         ('s/\@top_builddir\@/' . $build_rx . '/g',
  2251.          'header-vars');
  2252.  
  2253.     open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
  2254.     print "automake: reading $amfile\n" if $verbose;
  2255.  
  2256.     $output_vars .= ("# $in_file_name generated automatically by automake "
  2257.              . $VERSION . " from $am_file_name\n");
  2258.  
  2259.     # Generate copyright for generated Makefile.in.
  2260.     $output_vars .= $gen_copyright;
  2261.  
  2262.     local ($saw_bk) = 0;
  2263.     local ($was_rule) = 0;
  2264.     local ($spacing) = '';
  2265.     local ($comment) = '';
  2266.     local ($last_var_name) = '';
  2267.     local ($blank) = 0;
  2268.  
  2269.     while (<AM_FILE>)
  2270.     {
  2271.     if (/$IGNORE_PATTERN/o)
  2272.     {
  2273.         # Merely delete comments beginning with two hashes.
  2274.     }
  2275.     elsif (/$WHITE_PATTERN/o)
  2276.     {
  2277.         # Stick a single white line before the incoming macro or rule.
  2278.         $spacing = "\n";
  2279.         $blank = 1;
  2280.     }
  2281.     elsif (/$COMMENT_PATTERN/o)
  2282.     {
  2283.         # Stick comments before the incoming macro or rule.  Make
  2284.         # sure a blank line preceeds comments.
  2285.         $spacing = "\n" unless $blank;
  2286.         $comment .= $spacing . $_;
  2287.         $spacing = '';
  2288.     }
  2289.     else
  2290.     {
  2291.         last;
  2292.     }
  2293.     }
  2294.  
  2295.     $output_vars .= $comment . "\n" . $header_vars;
  2296.     $comment = '';
  2297.     $spacing = "\n";
  2298.  
  2299.     local ($is_ok_macro);
  2300.     while ($_)
  2301.     {
  2302.     $_ .= "\n"
  2303.         unless substr ($_, -1, 1) eq "\n";
  2304.  
  2305.     $_ =~ s/\@MAINT\@//g
  2306.         unless $seen_maint_mode;
  2307.  
  2308.     if (/$IGNORE_PATTERN/o)
  2309.     {
  2310.         # Merely delete comments beginning with two hashes.
  2311.     }
  2312.     elsif (/$WHITE_PATTERN/o)
  2313.     {
  2314.         # Stick a single white line before the incoming macro or rule.
  2315.         $spacing = "\n";
  2316.     }
  2317.     elsif (/$COMMENT_PATTERN/o)
  2318.     {
  2319.         # Stick comments before the incoming macro or rule.
  2320.         $comment .= $spacing . $_;
  2321.         $spacing = '';
  2322.     }
  2323.     elsif ($saw_bk)
  2324.     {
  2325.         if ($was_rule)
  2326.         {
  2327.         $output_trailer .= $_;
  2328.         $saw_bk = /\\$/;
  2329.         }
  2330.         else
  2331.         {
  2332.         $output_vars .= $_;
  2333.         $saw_bk = /\\$/;
  2334.         # Chop newline and backslash if this line is
  2335.         # continued.  FIXME maybe ensure trailing whitespace
  2336.         # exists?
  2337.         chop if $saw_bk;
  2338.         chop if $saw_bk;
  2339.         $contents{$last_var_name} .= $_;
  2340.         }
  2341.     }
  2342.     elsif (/$RULE_PATTERN/o)
  2343.     {
  2344.         # warn "** Saw rule .$1.\n";
  2345.         # Found a rule.
  2346.         $was_rule = 1;
  2347.         # Value here doesn't matter; for targets we only note
  2348.         # existence.
  2349.         $contents{$1} = 1;
  2350.         $targets{$1} = 1;
  2351.         $content_lines{$1} = $.;
  2352.         $output_trailer .= $comment . $spacing . $_;
  2353.         $comment = $spacing = '';
  2354.         $saw_bk = /\\$/;
  2355.     }
  2356.     elsif (($is_ok_macro = /$MACRO_PATTERN/o)
  2357.            || /$BOGUS_MACRO_PATTERN/o)
  2358.     {
  2359.         # Found a macro definition.
  2360.         $was_rule = 0;
  2361.         $last_var_name = $1;
  2362.         if (substr ($2, -1) eq "\\")
  2363.         {
  2364.         $contents{$1} = substr ($2, 0, length ($2) - 1);
  2365.         }
  2366.         else
  2367.         {
  2368.         $contents{$1} = $2;
  2369.         }
  2370.         $content_lines{$1} = $.;
  2371.         $output_vars .= $comment . $spacing . $_;
  2372.         $comment = $spacing = '';
  2373.         $saw_bk = /\\$/;
  2374.  
  2375.         # Error if bogus.
  2376.         &am_line_error ($., "bad macro name \`$1'")
  2377.         if ! $is_ok_macro;
  2378.     }
  2379.     else
  2380.     {
  2381.         # This isn't an error; it is probably a continued rule.
  2382.         # In fact, this is what we assume.
  2383.         $was_rule = 1;
  2384.         $output_trailer .= $comment . $spacing . $_;
  2385.         $comment = $spacing = '';
  2386.         $saw_bk = /\\$/;
  2387.     }
  2388.  
  2389.     $_ = <AM_FILE>;
  2390.     }
  2391.  
  2392.     $output_trailer .= $comment;
  2393. }
  2394.  
  2395. ################################################################
  2396.  
  2397. sub initialize_global_constants
  2398. {
  2399.     # Associative array of standard directory names.  Entry is TRUE if
  2400.     # corresponding directory should be installed during
  2401.     # 'install-exec' phase.
  2402.     %exec_dir_p =
  2403.     ('bin', 1,
  2404.      'sbin', 1,
  2405.      'libexec', 1,
  2406.      'data', 0,
  2407.      'sysconf', 1,
  2408.      'localstate', 1,
  2409.      'lib', 1,
  2410.      'info', 0,
  2411.      'man', 0,
  2412.      'include', 0,
  2413.      'oldinclude', 0,
  2414.      'pkgdata', 0,
  2415.      'pkglib', 1,
  2416.      'pkginclude', 0
  2417.      );
  2418.  
  2419.     # Helper text for dealing with man pages.
  2420.     $install_man_format =
  2421.     '    @sect=@SECTION@;                \\
  2422.     inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
  2423.     echo installing @MAN@ as $(mandir)/man$$sect/$$inst; \\
  2424.     $(INSTALL_DATA) $(srcdir)/@MAN@ $(mandir)/man$$sect/$$inst
  2425. ';
  2426.  
  2427.     $uninstall_man_format =
  2428.     '    inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
  2429.     rm -f $(mandir)/man@SECTION@/$$inst
  2430. ';
  2431.  
  2432.     # Commonly found files we look for and automatically include in
  2433.     # DISTFILES.
  2434.     @common_files =
  2435.     (
  2436.      "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
  2437.      "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
  2438.      "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
  2439.      "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh"
  2440.      );
  2441.  
  2442.     # Commonly used files we auto-include, but only sometimes.
  2443.     @common_sometimes =
  2444.     (
  2445.      "version.texi", "aclocal.m4", "acconfig.h", "config.h.top",
  2446.      "config.h.bot", "stamp-h.in", "ansi2knr.c",
  2447.      "ansi2knr.1", 'stamp-vti'
  2448.      );
  2449.  
  2450.     $USAGE = "\
  2451.   --amdir=DIR           directory storing config files
  2452.   --foreign             same as --strictness=foreign
  2453.   --gnits               same as --strictness=gnits
  2454.   --gnu                 same as --strictness=gnu
  2455.   --help                print this help, then exit
  2456.   -i, --include-deps    include generated dependencies in Makefile.in
  2457.   -a, --add-missing     add missing standard files to package
  2458.   -o DIR, --output-dir=DIR
  2459.                         put generated Makefile.in's into DIR
  2460.   -s LEVEL, --strictness=LEVEL
  2461.                         set strictness level.  LEVEL is foreign, gnu, gnits
  2462.   -v, --verbose         verbosely list files processed
  2463.   --version             print version number, then exit\n";
  2464.  
  2465.     # Copyright on generated Makefile.ins.
  2466.     $gen_copyright = "\
  2467. # Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
  2468. # This Makefile.in is free software; the Free Software Foundation
  2469. # gives unlimited permission to copy, distribute and modify it.
  2470. ";
  2471. }
  2472.  
  2473. # (Re)-Initialize per-Makefile.am variables.
  2474. sub initialize_per_input
  2475. {
  2476.     # These two variables are used when generating each Makefile.in.
  2477.     # They hold the Makefile.in until it is ready to be printed.
  2478.     $output_rules = '';
  2479.     $output_vars = '';
  2480.     $output_trailer = '';
  2481.  
  2482.     # Suffixes found during a run.
  2483.     @suffixes = ();
  2484.  
  2485.     # This holds the contents of a Makefile.am, as parsed by
  2486.     # read_am_file.
  2487.     %contents = ();
  2488.  
  2489.     # This holds the names which are targets.  These also appear in
  2490.     # %contents.
  2491.     %targets = ();
  2492.  
  2493.     # This holds the line numbers at which various elements of
  2494.     # %contents are defined.
  2495.     %content_lines = ();
  2496.  
  2497.     # This holds the "relative directory" of the current Makefile.in.
  2498.     # Eg for src/Makefile.in, this is "src".
  2499.     $relative_dir = '';
  2500.  
  2501.     # This holds a list of files that are included in the
  2502.     # distribution.
  2503.     %dist_common = ();
  2504.  
  2505.     # List of dependencies for the obvious targets.
  2506.     @install_data = ();
  2507.     @install_exec = ();
  2508.     @uninstall = ();
  2509.     @installdirs = ();
  2510.  
  2511.     @info = ();
  2512.     @dvi = ();
  2513.     @all = ();
  2514.     @check = ();
  2515.     @installcheck = ();
  2516.     @clean = ();
  2517.  
  2518.     @phony = ();
  2519.  
  2520.     # These are pretty obvious, too.  They are used to define the
  2521.     # SOURCES and OBJECTS variables.
  2522.     @sources = ();
  2523.     @objects = ();
  2524.  
  2525.     # TRUE if current directory holds any C source files.  (Actually
  2526.     # holds object extension, but this information is encapsulated in
  2527.     # the function get_object_extension).
  2528.     $dir_holds_sources = '';
  2529.  
  2530.     # TRUE if install targets should work recursively.
  2531.     $recursive_install = 0;
  2532.  
  2533.     # All .P files.
  2534.     %dep_files = ();
  2535.  
  2536.     # Strictness levels.
  2537.     $strictness = $default_strictness;
  2538.     $strictness_name = $default_strictness_name;
  2539.  
  2540.     # Options from AUTOMAKE_OPTIONS.
  2541.     %options = ();
  2542.  
  2543.     # Whether or not dependencies are handled.  Can be further changed
  2544.     # in handle_options.
  2545.     $use_dependencies = $cmdline_use_dependencies;
  2546.  
  2547.     # Per Makefile.am.
  2548.     $local_maint_charset = $maint_charset;
  2549. }
  2550.  
  2551.  
  2552. ################################################################
  2553.  
  2554. # Return contents of a file from $am_dir, automatically skipping
  2555. # macros or rules which are already known.  Runs command on each line
  2556. # as it is read; this command can modify $_.
  2557. sub file_contents_with_transform
  2558. {
  2559.     local ($command, $basename) = @_;
  2560.     local ($file) = $am_dir . '/' . $basename . '.am';
  2561.  
  2562.     open (FC_FILE, $file)
  2563.     || die "automake: installation error: cannot open \`$file'\n";
  2564.     # Looks stupid?
  2565.     # print "automake: reading $file\n" if $verbose;
  2566.  
  2567.     local ($was_rule) = 0;
  2568.     local ($result_vars) = '';
  2569.     local ($result_rules) = '';
  2570.     local ($comment) = '';
  2571.     local ($spacing) = "\n";
  2572.     local ($skipping) = 0;
  2573.  
  2574.     while (<FC_FILE>)
  2575.     {
  2576.     $_ =~ s/\@MAINT\@//g
  2577.         unless $seen_maint_mode;
  2578.  
  2579.     eval $command;
  2580.  
  2581.     if (/$IGNORE_PATTERN/o)
  2582.     {
  2583.         # Merely delete comments beginning with two hashes.
  2584.     }
  2585.     elsif (/$WHITE_PATTERN/o)
  2586.     {
  2587.         # Stick a single white line before the incoming macro or rule.
  2588.         $spacing = "\n";
  2589.     }
  2590.     elsif (/$COMMENT_PATTERN/o)
  2591.     {
  2592.         # Stick comments before the incoming macro or rule.
  2593.         $comment .= $spacing . $_;
  2594.         $spacing = '';
  2595.     }
  2596.     elsif ($saw_bk)
  2597.     {
  2598.         if ($was_rule)
  2599.         {
  2600.         $result_rules .= $_ if ! $skipping;
  2601.         }
  2602.         else
  2603.         {
  2604.         $result_vars .= $_ if ! $skipping;
  2605.         }
  2606.         $saw_bk = /\\$/;
  2607.     }
  2608.     elsif (/$RULE_PATTERN/o)
  2609.     {
  2610.         # warn "** Found rule .$1.\n";
  2611.         # Found a rule.
  2612.         $was_rule = 1;
  2613.         $skipping = defined $contents{$1};
  2614.         # warn "** Skip $skipping\n" if $skipping;
  2615.         $result_rules .= $comment . $spacing . $_ if ! $skipping;
  2616.         $comment = $spacing = '';
  2617.         $saw_bk = /\\$/;
  2618.     }
  2619.     elsif (/$MACRO_PATTERN/o)
  2620.     {
  2621.         # warn "** Found macro .$1.\n";
  2622.         # Found a variable reference.
  2623.         $was_rule = 0;
  2624.         $skipping = defined $contents{$1};
  2625.         # warn "** Skip $skipping\n" if $skipping;
  2626.         $result_vars .= $comment . $spacing . $_ if ! $skipping;
  2627.         $comment = $spacing = '';
  2628.         $saw_bk = /\\$/;
  2629.     }
  2630.     else
  2631.     {
  2632.         # This isn't an error; it is probably a continued rule.
  2633.         # In fact, this is what we assume.
  2634.         $was_rule = 1;
  2635.         $result_rules .= $comment . $spacing . $_ if ! $skipping;
  2636.         $comment = $spacing = '';
  2637.         $saw_bk = /\\$/;
  2638.     }
  2639.     }
  2640.  
  2641.     close (FC_FILE);
  2642.     return $result_vars . $result_rules . $comment;
  2643. }
  2644.  
  2645. # Like file_contents_with_transform, but no transform.
  2646. sub file_contents
  2647. {
  2648.     return &file_contents_with_transform ('', @_);
  2649. }
  2650.  
  2651. # Handle `where_HOW' variable magic.  Does all lookups, generates
  2652. # install code, and possibly generates code to define the primary
  2653. # variable.  The first argument is the name of the .am file to munge,
  2654. # the second argument is the primary variable (eg HEADERS), and all
  2655. # subsequent arguments are possible installation locations.  Returns
  2656. # list of all values of all _HOW targets.
  2657. #
  2658. # FIXME this should be rewritten to be cleaner.  It should be broken
  2659. # up into multiple functions.
  2660. #
  2661. # Usage is: am_install_var (OPTION..., file, HOW, where...)
  2662. sub am_install_var
  2663. {
  2664.     local (@args) = @_;
  2665.  
  2666.     local ($do_all, $do_clean) = (1, 0);
  2667.     while (@args)
  2668.     {
  2669.     if ($args[0] eq '-clean')
  2670.     {
  2671.         $do_clean = 1;
  2672.     }
  2673.     elsif ($args[0] eq '-no-all')
  2674.     {
  2675.         $do_all = 0;
  2676.     }
  2677.     elsif ($args[0] !~ /^-/)
  2678.     {
  2679.         last;
  2680.     }
  2681.     shift (@args);
  2682.     }
  2683.     local ($file, $primary, @prefixes) = @args;
  2684.  
  2685.     local (@used) = ();
  2686.     local (@result) = ();
  2687.  
  2688.     # Now that configure substitutions are allowed in where_HOW
  2689.     # variables, it is an error to actually define the primary.
  2690.     &am_line_error ($primary, "\`$primary' is an anachronism")
  2691.     if &variable_defined ($primary);
  2692.  
  2693.  
  2694.     # Look for misspellings.  It is an error to have a variable ending
  2695.     # in a "reserved" suffix whose prefix is unknown, eg
  2696.     # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
  2697.     # variable of the same name (with "dir" appended) exists.  For
  2698.     # instance, if the variable "zardir" is defined, then
  2699.     # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
  2700.     # flexibility in those cases which need it.  Perhaps it should be
  2701.     # disallowed in the Gnits case?  The problem is, sometimes it is
  2702.     # useful to put things in a subdir of eg pkgdatadir, perhaps even
  2703.     # for Gnitsoids.
  2704.     local (%valid, $varname);
  2705.     grep ($valid{$_} = 0, @prefixes);
  2706.     $valid{'EXTRA'} = 0;
  2707.     foreach $varname (keys %contents)
  2708.     {
  2709.     if ($varname =~ /^(.*)_$primary$/)
  2710.     {
  2711.         if (! defined $valid{$1} && ! &variable_defined ($1 . 'dir'))
  2712.         {
  2713.         &am_line_error ($varname, "invalid variable \"$varname\"");
  2714.         }
  2715.         else
  2716.         {
  2717.         # Ensure all extended prefixes are actually used.
  2718.         $valid{$1} = 1;
  2719.         }
  2720.     }
  2721.     }
  2722.  
  2723.     local ($clean_file) = $file . '-clean';
  2724.     local ($one_name);
  2725.     local ($X);
  2726.     foreach $X (keys %valid)
  2727.     {
  2728.     $one_name = $X . '_' . $primary;
  2729.     if (&variable_defined ($one_name))
  2730.     {
  2731.         # Append actual contents of where_PRIMARY variable to
  2732.         # result.
  2733.         local ($rcurs);
  2734.         foreach $rcurs (split (' ', $contents{$one_name}))
  2735.         {
  2736.         # Skip configure substitutions.  Possibly bogus.
  2737.         next if $rcurs =~ /^\@.*\@$/;
  2738.         push (@result, $rcurs);
  2739.         }
  2740.  
  2741.         # "EXTRA" shouldn't be used when generating clean targets,
  2742.         # @all, or install targets.
  2743.         next if $X eq 'EXTRA';
  2744.  
  2745.         if ($do_clean)
  2746.         {
  2747.         $output_rules .=
  2748.             &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
  2749.                            $clean_file);
  2750.  
  2751.         push (@clean, $X . $primary);
  2752.         &push_phony_cleaners ($X . $primary);
  2753.         }
  2754.  
  2755.         if ($X eq 'check')
  2756.         {
  2757.         push (@check, '$(' . $one_name . ')');
  2758.         }
  2759.         else
  2760.         {
  2761.         push (@used, '$(' . $one_name . ')');
  2762.         }
  2763.         if ($X eq 'noinst' || $X eq 'check')
  2764.         {
  2765.         # Objects which don't get installed by default.
  2766.         next;
  2767.         }
  2768.  
  2769.         $output_rules .=
  2770.         &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
  2771.                            $file);
  2772.  
  2773.         push (@uninstall, 'uninstall-' . $X . $primary);
  2774.         push (@phony, 'uninstall-' . $X . $primary);
  2775.         push (@installdirs, '$(' . $X . 'dir)');
  2776.         if ($exec_dir_p{$X})
  2777.         {
  2778.         push (@install_exec, 'install-' . $X . $primary);
  2779.         push (@phony, 'install-' . $X . $primary);
  2780.         }
  2781.         else
  2782.         {
  2783.         push (@install_data, 'install-' . $X . $primary);
  2784.         push (@phony, 'install-' . $X . $primary);
  2785.         }
  2786.     }
  2787.     }
  2788.  
  2789.     if (@used)
  2790.     {
  2791.     # Define it.
  2792.     &pretty_print ($primary . ' =', '', @used);
  2793.     $output_vars .= "\n";
  2794.     }
  2795.  
  2796.     # Push here because PRIMARY might be configure time determined.
  2797.     push (@all, '$(' . $primary . ')')
  2798.     if $do_all && @used;
  2799.  
  2800.     return (@result);
  2801. }
  2802.  
  2803.  
  2804. ################################################################
  2805.  
  2806. # This variable is local to the "require file" set of functions.
  2807. @require_file_paths = ();
  2808.  
  2809. # Verify that the file must exist in the current directory.  Usage:
  2810. # require_file (isconfigure, line_number, strictness, file) strictness
  2811. # is the strictness level at which this file becomes required.  Must
  2812. # set require_file_paths before calling this function.
  2813. # require_file_paths is set to hold a single directory (the one in
  2814. # which the first file was found) before return.
  2815. sub require_file_internal
  2816. {
  2817.     local ($is_configure, $line, $mystrict, @files) = @_;
  2818.     local ($file, $fullfile);
  2819.     local ($found_it, $errfile, $errdir);
  2820.     local ($save_dir);
  2821.  
  2822.     foreach $file (@files)
  2823.     {
  2824.     $found_it = 0;
  2825.     foreach $dir (@require_file_paths)
  2826.     {
  2827.         if ($dir eq '.')
  2828.         {
  2829.         $fullfile = $relative_dir . "/" . $file;
  2830.         $errdir = $relative_dir unless $errdir;
  2831.         }
  2832.         else
  2833.         {
  2834.         $fullfile = $dir . "/" . $file;
  2835.         $errdir = $dir unless $errdir;
  2836.         }
  2837.  
  2838.         # Use different name for "error filename".  Otherwise on
  2839.         # an error the bad file will be reported as eg
  2840.         # `../../install-sh' when using the default
  2841.         # config_aux_path.
  2842.         $errfile = $errdir . '/' . $file;
  2843.  
  2844.         if (-f $fullfile)
  2845.         {
  2846.         $found_it = 1;
  2847.         &push_dist_common ($file) if $dir eq $relative_dir;
  2848.         $save_dir = $dir;
  2849.         last;
  2850.         }
  2851.     }
  2852.  
  2853.     if ($found_it)
  2854.     {
  2855.         # Prune the path list.
  2856.         @require_file_paths = $save_dir;
  2857.     }
  2858.     else
  2859.     {
  2860.         if ($strictness >= $mystrict)
  2861.         {
  2862.         # Only install missing files according to our desired
  2863.         # strictness level.
  2864.         if ($add_missing && -f ($am_dir . '/' . $file))
  2865.         {
  2866.             # Install the missing file.  Symlink if we can, copy
  2867.             # if we must.
  2868.             if ($symlink_exists)
  2869.             {
  2870.             symlink ($am_dir . '/' . $file, $errfile);
  2871.             }
  2872.             else
  2873.             {
  2874.             system ('cp', $am_dir . '/' . $file, $errfile);
  2875.             }
  2876.  
  2877.             # FIXME this is a hack.  Should have am_warn.
  2878.             local ($save) = $exit_status;
  2879.             if ($is_configure)
  2880.             {
  2881.             &am_conf_line_error
  2882.                 ($line,
  2883.                  "required file \"$errfile\" not found; installing");
  2884.             }
  2885.             else
  2886.             {
  2887.             &am_line_error
  2888.                 ($line,
  2889.                  "required file \"$errfile\" not found; installing");
  2890.             }
  2891.             $exit_status = $save;
  2892.         }
  2893.         else
  2894.         {
  2895.             # Only an error if strictness constraint violated.
  2896.             if ($is_configure)
  2897.             {
  2898.             &am_conf_line_error
  2899.                 ($line, "required file \"$errfile\" not found");
  2900.             }
  2901.             else
  2902.             {
  2903.             &am_line_error
  2904.                 ($line, "required file \"$errfile\" not found");
  2905.             }
  2906.         }
  2907.         }
  2908.     }
  2909.     }
  2910. }
  2911.  
  2912. # Like require_file_with_line, but error messages refer to
  2913. # configure.in, not the current Makefile.am.
  2914. sub require_file_with_conf_line
  2915. {
  2916.     @require_file_paths = '.';
  2917.     &require_file_internal (1, @_);
  2918. }
  2919.  
  2920. sub require_file_with_line
  2921. {
  2922.     @require_file_paths = '.';
  2923.     &require_file_internal (0, @_);
  2924. }
  2925.  
  2926. sub require_file
  2927. {
  2928.     @require_file_paths = '.';
  2929.     &require_file_internal (0, '', @_);
  2930. }
  2931.  
  2932. # Require a file that is also required by Autoconf.  Looks in
  2933. # configuration path, as specified by AC_CONFIG_AUX_DIR.
  2934. sub require_config_file
  2935. {
  2936.     @require_file_paths = @config_aux_path;
  2937.     &require_file_internal (0, '', @_);
  2938.     local ($dir) = $require_file_paths[0];
  2939.     @config_aux_path = @require_file_paths;
  2940.     if ($dir eq '.')
  2941.     {
  2942.     $config_aux_dir = '.';
  2943.     }
  2944.     else
  2945.     {
  2946.     $config_aux_dir = '$(top_srcdir)/' . $dir;
  2947.     }
  2948. }
  2949.  
  2950. # Assumes that the line number is in Makefile.am.
  2951. sub require_conf_file_with_line
  2952. {
  2953.     @require_file_paths = @config_aux_path;
  2954.     &require_file_internal (0, @_);
  2955.     local ($dir) = $require_file_paths[0];
  2956.     @config_aux_path = @require_file_paths;
  2957.     if ($dir eq '.')
  2958.     {
  2959.     $config_aux_dir = '.';
  2960.     }
  2961.     else
  2962.     {
  2963.     $config_aux_dir = '$(top_srcdir)/' . $dir;
  2964.     }
  2965. }
  2966.  
  2967. # Assumes that the line number is in Makefile.am.
  2968. sub require_conf_file_with_conf_line
  2969. {
  2970.     @require_file_paths = @config_aux_path;
  2971.     &require_file_internal (1, @_);
  2972.     local ($dir) = $require_file_paths[0];
  2973.     @config_aux_path = @require_file_paths;
  2974.     if ($dir eq '.')
  2975.     {
  2976.     $config_aux_dir = '.';
  2977.     }
  2978.     else
  2979.     {
  2980.     $config_aux_dir = '$(top_srcdir)/' . $dir;
  2981.     }
  2982. }
  2983.  
  2984. ################################################################
  2985.  
  2986. # Push a list of files onto dist_common.
  2987. sub push_dist_common
  2988. {
  2989.     local (@files) = @_;
  2990.     local ($file);
  2991.  
  2992.     foreach $file (@files)
  2993.     {
  2994.     $dist_common{$file} = 1;
  2995.     }
  2996. }
  2997.  
  2998. # Push a list of clean targets onto phony.
  2999. sub push_phony_cleaners
  3000. {
  3001.     local ($base) = @_;
  3002.     local ($target);
  3003.     foreach $target ('mostly', 'dist', '', 'maintainer-')
  3004.     {
  3005.     push (@phony, $target . 'clean-' . $base);
  3006.     }
  3007. }
  3008.  
  3009. # Set strictness.
  3010. sub set_strictness
  3011. {
  3012.     $strictness_name = $_[0];
  3013.     if ($strictness_name eq 'gnu')
  3014.     {
  3015.     $strictness = $GNU;
  3016.     }
  3017.     elsif ($strictness_name eq 'gnits')
  3018.     {
  3019.     $strictness = $GNITS;
  3020.     }
  3021.     elsif ($strictness_name eq 'foreign')
  3022.     {
  3023.     $strictness = $FOREIGN;
  3024.     }
  3025.     else
  3026.     {
  3027.     die "automake: level \`$strictness_name' not recognized\n";
  3028.     }
  3029. }
  3030.  
  3031.  
  3032. ################################################################
  3033.  
  3034. # Return directory name of file.
  3035. sub dirname
  3036. {
  3037.     local ($file) = @_;
  3038.     local ($sub);
  3039.  
  3040.     ($sub = $file) =~ s,/+[^/]+$,,g;
  3041.     $sub = '.' if $sub eq $file;
  3042.     return $sub;
  3043. }
  3044.  
  3045. # Make a directory.
  3046. sub mkdir
  3047. {
  3048.     local ($dirname) = @_;
  3049.     system ("mkdir", $dirname);
  3050. }
  3051.  
  3052. ################################################################
  3053.  
  3054. # Print an error message and set exit status.
  3055. sub am_error
  3056. {
  3057.     warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
  3058.     $exit_status = 1;
  3059. }
  3060.  
  3061. sub am_line_error
  3062. {
  3063.     local ($symbol, @args) = @_;
  3064.  
  3065.     if ($symbol)
  3066.     {
  3067.     # If SYMBOL not already a line number, look it up in Makefile.am.
  3068.     $symbol = $content_lines{$symbol} unless $symbol =~ /^\d+$/;
  3069.     $symbol .= ': ' if $symbol;
  3070.     warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
  3071.     $exit_status = 1;
  3072.     }
  3073.     else
  3074.     {
  3075.     &am_error (@args);
  3076.     }
  3077. }
  3078.  
  3079. # Like am_error, but while scanning configure.in.
  3080. sub am_conf_error
  3081. {
  3082.     # FIXME can run in subdirs.
  3083.     warn "automake: configure.in: ", join (' ', @_), "\n";
  3084.     $exit_status = 1;
  3085. }
  3086.  
  3087. # Error message with line number referring to configure.in.
  3088. sub am_conf_line_error
  3089. {
  3090.     local ($line, @args) = @_;
  3091.  
  3092.     if ($line)
  3093.     {
  3094.     warn "configure.in: $line: ", join (' ', @args), "\n";
  3095.     $exit_status = 1;
  3096.     }
  3097.     else
  3098.     {
  3099.     &am_conf_error (@args);
  3100.     }
  3101. }
  3102.  
  3103. # Tell user where our aclocal.m4 is, but only once.
  3104. sub keyed_aclocal_warning
  3105. {
  3106.     local ($key) = @_;
  3107.     warn "automake: macro \`$key' can be found in ${am_dir}/aclocal.m4\n";
  3108. }
  3109.  
  3110. # Print usage information.
  3111. sub usage
  3112. {
  3113.     print "Usage: automake [OPTION] ... [Makefile]...\n";
  3114.     print $USAGE;
  3115.     print "\nFiles which are automatically distributed, if found:\n";
  3116.     $~ = "USAGE_FORMAT";
  3117.     local (@lcomm) = sort ((@common_files, @common_sometimes));
  3118.     local ($one, $two, $three, $four);
  3119.     while (@lcomm > 0)
  3120.     {
  3121.     $one = shift @lcomm;
  3122.     $two = @lcomm ? shift @lcomm : '';
  3123.     $three = @lcomm ? shift @lcomm : '';
  3124.     $four = @lcomm ? shift @lcomm : '';
  3125.     write;
  3126.     }
  3127.  
  3128.     exit 0;
  3129. }
  3130.  
  3131. format USAGE_FORMAT =
  3132.   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
  3133.   $one,               $two,               $three,             $four
  3134. .
  3135.